Skip to content

Commit

Permalink
Use maven 3.9 by default, make maven4 optional using profiles (#13)
Browse files Browse the repository at this point in the history
* Use maven 3.9 by default, make maven4 optional using profiles
* Add maven 3/4 in the CI matrix
  • Loading branch information
gnodet committed May 16, 2022
1 parent 64213cd commit 01a04f4
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 48 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
matrix:
os: [ubuntu-latest, macOS-latest]
java: [11, 17]
maven: [maven3, maven4]
fail-fast: false

runs-on: ${{ matrix.os }}
Expand All @@ -49,5 +50,5 @@ jobs:
${{ runner.os }}-maven-
- name: Build with Maven
run: mvn install -e -B -V
run: mvn install -e -B -V -P${{ matrix.maven }}

127 changes: 93 additions & 34 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ under the License.
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<classWorldsVersion>2.6.0</classWorldsVersion>
<maven3Version>3.9.0-SNAPSHOT</maven3Version><!-- MNG-7391-maven-3.8.x branch, waiting for MNG-7391 Maven API update -->
<maven4Version>4.0.0-alpha-1-SNAPSHOT</maven4Version><!-- MNG-7391-master branch, waiting for MNG-7391 Maven API update -->
<maven3Version>3.9.0-SNAPSHOT</maven3Version>
<maven4Version>4.0.0-alpha-1-SNAPSHOT</maven4Version>

<formatter-maven-plugin.version>2.17.0</formatter-maven-plugin.version>
<impsort-maven-plugin.version>1.6.2</impsort-maven-plugin.version>
Expand Down Expand Up @@ -94,7 +94,7 @@ under the License.
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${maven4Version}</version>
<version>${maven3Version}</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -365,37 +365,6 @@ under the License.
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy-maven-distributions</id>
<phase>pre-integration-test</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.apache.maven</groupId>
<artifactId>apache-maven</artifactId>
<version>${maven3Version}</version>
<classifier>bin</classifier>
<type>tar.gz</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/maven3</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>org.apache.maven</groupId>
<artifactId>apache-maven</artifactId>
<version>${maven4Version}</version>
<classifier>bin</classifier>
<type>tar.gz</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/maven4</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -411,4 +380,94 @@ under the License.
</plugins>
</build>

<profiles>
<profile>
<id>maven3</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-maven3-distributions</id>
<phase>pre-integration-test</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.apache.maven</groupId>
<artifactId>apache-maven</artifactId>
<version>${maven3Version}</version>
<classifier>bin</classifier>
<type>tar.gz</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/maven3</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemProperties>
<with-maven3>true</with-maven3>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>maven4</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-maven4-distributions</id>
<phase>pre-integration-test</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.apache.maven</groupId>
<artifactId>apache-maven</artifactId>
<version>${maven4Version}</version>
<classifier>bin</classifier>
<type>tar.gz</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/maven4</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemProperties>
<with-maven4>true</with-maven4>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContex
ExtensionContext extensionContext )
{
Method m = extensionContext.getRequiredTestMethod();
return Stream.of( maven3, maven4 ).map( p -> new MavenTemplate( m, p ) );
return Stream.concat( maven3 != null ? Stream.of( maven3 ) : Stream.empty(),
maven4 != null ? Stream.of( maven4 ) : Stream.empty() )
.map( p -> new MavenTemplate( m, p ) );
}

private static void buildMaven() throws Exception
Expand All @@ -81,20 +83,26 @@ private static void buildMaven() throws Exception
// "The 'maven.multiModuleProjectDirectory' system property need to be set" );

// maven3
maven3 = Files.list( Paths.get( "target/maven3" ) )
.filter( f -> f.getFileName().toString().startsWith( "apache-maven" ) && Files.isDirectory( f ) )
.findFirst()
.orElseThrow( () -> new IllegalStateException( "Unable to find maven3 directory" ) )
.toAbsolutePath();
maven3.resolve( "bin/mvn" ).toFile().setExecutable( true );
if ( Boolean.getBoolean( "with-maven3" ) )
{
maven3 = Files.list( Paths.get( "target/maven3" ) )
.filter( f -> f.getFileName().toString().startsWith( "apache-maven" ) && Files.isDirectory( f ) )
.findFirst()
.map( Path::toAbsolutePath )
.orElseThrow( () -> new IllegalStateException( "Unable to find maven3 directory" ) );
maven3.resolve( "bin/mvn" ).toFile().setExecutable( true );
}

// maven4
maven4 = Files.list( Paths.get( "target/maven4" ) )
.filter( f -> f.getFileName().toString().startsWith( "apache-maven" ) && Files.isDirectory( f ) )
.findFirst()
.orElseThrow( () -> new IllegalStateException( "Unable to find maven4 directory" ) )
.toAbsolutePath();
maven4.resolve( "bin/mvn" ).toFile().setExecutable( true );
if ( Boolean.getBoolean( "with-maven4" ) )
{
maven4 = Files.list( Paths.get( "target/maven4" ) )
.filter( f -> f.getFileName().toString().startsWith( "apache-maven" ) && Files.isDirectory( f ) )
.findFirst()
.map( Path::toAbsolutePath )
.orElse( null );
maven4.resolve( "bin/mvn" ).toFile().setExecutable( true );
}

initialized = true;
}
Expand Down

0 comments on commit 01a04f4

Please sign in to comment.