Skip to content

Commit

Permalink
Enable automatic source formatting via Maven plugins.
Browse files Browse the repository at this point in the history
Signed-off-by: James R. Perkins <[email protected]>
  • Loading branch information
jamezp committed Jun 28, 2024
1 parent e12e22c commit 73c012f
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 3 deletions.
30 changes: 27 additions & 3 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ concurrency:
cancel-in-progress: true

jobs:
build-:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest ]
java: ['11', '17', '21']
java: ['17', '21']

steps:
- uses: actions/checkout@v4
Expand All @@ -40,7 +40,31 @@ jobs:
distribution: 'temurin'
cache: 'maven'
- name: Build with Maven Java ${{ matrix.java }}
run: mvn -B clean verify
run: mvn -B -ntp clean verify
- uses: actions/upload-artifact@v4
if: failure()
with:
name: surefire-reports-${{ matrix.os }}-${{ matrix.java }}
path: '**/surefire-reports/*'
test-java11:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest ]

steps:
- uses: actions/checkout@v4
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v4
with:
java-version: |
11
17
distribution: 'temurin'
cache: 'maven'
- name: Build with Maven Java ${{ matrix.java }}
run: mvn -B -ntp clean verify '-Djava11.home="${{env.JAVA_HOME_11_X64}}"'
- uses: actions/upload-artifact@v4
if: failure()
with:
Expand Down
103 changes: 103 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,20 @@

<!-- Properties -->
<properties>
<maven.compile.release>11</maven.compile.release>
<jdk.min.version>17</jdk.min.version>

<!-- Dependency versions -->
<version.arquillian_core>1.8.0.Final</version.arquillian_core>
<version.testcontainers>1.19.8</version.testcontainers>

<!-- Plugin versions -->
<version.formatter.maven.plugin>2.23.0</version.formatter.maven.plugin>
<version.impsort.maven.plugin>1.11.0</version.impsort.maven.plugin>

<!-- Configuration properties -->
<skipFormatting>false</skipFormatting>
<maven.test.redirectTestOutputToFile>true</maven.test.redirectTestOutputToFile>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -124,7 +136,98 @@
<localCheckout>true</localCheckout>
</configuration>
</plugin>
<!-- Enable auto-formatting of source files -->
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>${version.formatter.maven.plugin}</version>
<dependencies>
<dependency>
<groupId>org.wildfly.tools</groupId>
<artifactId>ide-config</artifactId>
<version>1.0.4.Final</version>
</dependency>
</dependencies>
<configuration>
<!-- store outside of target to speed up formatting when mvn clean is used -->
<cachedir>.cache</cachedir>
<configFile>eclipse-code-formatter.xml</configFile>
<configXmlFile>wildfly-xml.properties</configXmlFile>
<lineEnding>LF</lineEnding>
<includeResources>true</includeResources>
<removeTrailingWhitespace>true</removeTrailingWhitespace>
<skip>${skipFormatting}</skip>
</configuration>
<executions>
<execution>
<id>format</id>
<goals>
<goal>format</goal>
</goals>
<phase>process-sources</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.revelc.code</groupId>
<artifactId>impsort-maven-plugin</artifactId>
<version>${version.impsort.maven.plugin}</version>
<configuration>
<!-- store outside of target to speed up formatting when mvn clean is used -->
<cachedir>.cache</cachedir>
<groups>java.,javax.,jakarta.,org.,com.</groups>
<staticGroups>*</staticGroups>
<skip>${skipFormatting}</skip>
<removeUnused>true</removeUnused>
</configuration>
<executions>
<execution>
<id>sort-imports</id>
<goals>
<goal>sort</goal>
</goals>
<phase>process-sources</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>format-check</id>
<build>
<plugins>
<!-- Validate formatting -->
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<executions>
<execution>
<id>validate-format</id>
<phase>validate</phase>
<goals>
<goal>validate</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.revelc.code</groupId>
<artifactId>impsort-maven-plugin</artifactId>
<executions>
<execution>
<id>check-import-sort</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

0 comments on commit 73c012f

Please sign in to comment.