sormuras commented on a change in pull request #196: [SUREFIRE-1585] [WIP] 
Resolve missing and align "JUnit 5" artifacts
URL: https://github.com/apache/maven-surefire/pull/196#discussion_r232499728
 
 

 ##########
 File path: 
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
 ##########
 @@ -2846,8 +2849,96 @@ public void addProviderProperties()
         @Nonnull
         public Set<Artifact> getProviderClasspath()
         {
+            String provider = "surefire-junit-platform";
             String version = surefireBooterArtifact.getBaseVersion();
-            return dependencyResolver.getProviderClasspath( 
"surefire-junit-platform", version );
+            Set<Artifact> providerArtifacts = 
dependencyResolver.getProviderClasspath( provider, version );
+            alignJUnitPlatformVersion( providerArtifacts );
+            resolveJUnitJupiterEngine( providerArtifacts );
+            resolveJUnitVintageEngine( providerArtifacts );
+            return providerArtifacts;
+        }
+
+        private void resolveJUnitJupiterEngine( Set<Artifact> 
providerArtifacts )
+        {
+            Artifact junitJupiterApi = getProjectArtifactMap().get( 
"org.junit.jupiter:junit-jupiter-api" );
+            if ( junitJupiterApi == null ) // no api, no engine
+            {
+                return;
+            }
+            Artifact junitJupiterEngine = getProjectArtifactMap().get( 
"org.junit.jupiter:junit-jupiter-engine" );
+            if ( junitJupiterEngine != null ) // engine already resolved by 
project
+            {
+                return;
+            }
+            // resolve "junit-jupiter-engine" and its transitive dependencies
+            String jupiterVersion = junitJupiterApi.getBaseVersion();
+            resolve( providerArtifacts, "org.junit.jupiter", 
"junit-jupiter-engine", jupiterVersion );
+        }
+
+        private void resolveJUnitVintageEngine( Set<Artifact> 
providerArtifacts )
+        {
+            Artifact junit = getProjectArtifactMap().get( "junit:junit" );
+            if ( junit == null ) // no api, no engine
+            {
+                return;
+            }
+            if ( !junit.getBaseVersion().equals( "4.12" ) ) // not "JUnit 
4.12", no engine
+            {
+                return;
+            }
+            Artifact junitVintageEngine = getProjectArtifactMap().get( 
"org.junit.vintage:junit-vintage-engine" );
+            if ( junitVintageEngine != null ) // engine already resolved by 
project
+            {
+                return;
+            }
+            // resolve "junit-vintage-engine" and its transitive dependencies
+            // heuristic: from Platform "x.y.z" to Vintage "5" + ".y.z"
 
 Review comment:
   > Who can say that the versions will be always like this?
   
   The @junit-team -- I guess, it'll stay like this "heuristic" for the next 
5-10 years.
   
   > Somebody has to watch the versions in Maven Central and still update this 
code.
   
   Sure. Unless we introduce a metadata engine artifact hint, like described 
here: https://github.com/junit-team/junit5/issues/1669
   
   > What if the version is not successfully resolved?
   
   The execution of Surefire fails for the project. Users may always provide 
the correct `junit-vintage-engine` in their project pom dependencies and 
prevent this code path to be executed.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to