@ -24,23 +24,22 @@ import java.util.List;
import me.champeau.gradle.japicmp.JapicmpPlugin ;
import me.champeau.gradle.japicmp.JapicmpPlugin ;
import me.champeau.gradle.japicmp.JapicmpTask ;
import me.champeau.gradle.japicmp.JapicmpTask ;
import org.gradle.api.Ac tion ;
import org.gradle.api.GradleExcep tion ;
import org.gradle.api.Plugin ;
import org.gradle.api.Plugin ;
import org.gradle.api.Project ;
import org.gradle.api.Project ;
import org.gradle.api.artifacts.Configuration ;
import org.gradle.api.artifacts.Configuration ;
import org.gradle.api.artifacts.Dependency ;
import org.gradle.api.artifacts.Dependency ;
import org.gradle.api.artifacts.repositories.ArtifactRepository ;
import org.gradle.api.artifacts.repositories.MavenArtifactRepository ;
import org.gradle.api.artifacts.repositories.RepositoryContentDescriptor ;
import org.gradle.api.plugins.JavaBasePlugin ;
import org.gradle.api.plugins.JavaBasePlugin ;
import org.gradle.api.plugins.JavaPlugin ;
import org.gradle.api.plugins.JavaPlugin ;
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin ;
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin ;
import org.gradle.api.tasks.TaskProvider ;
import org.gradle.api.tasks.TaskProvider ;
import org.gradle.jvm.tasks.Jar ;
import org.gradle.jvm.tasks.Jar ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
/ * *
/ * *
* { @link Plugin } that applies the { @code "japicmp-gradle-plugin" }
* { @link Plugin } that applies the { @code "japicmp-gradle-plugin" }
* and create tasks for all subprojects , diffing the public API one by one
* and create tasks for all subprojects named { @code "spring-*" } , diffing the public API one by one
* and creating the reports in { @code "build/reports/api-diff/$OLDVERSION_to_$NEWVERSION/" } .
* and creating the reports in { @code "build/reports/api-diff/$OLDVERSION_to_$NEWVERSION/" } .
* < p > { @code "./gradlew apiDiff -PbaselineVersion=5.1.0.RELEASE" } will output the
* < p > { @code "./gradlew apiDiff -PbaselineVersion=5.1.0.RELEASE" } will output the
* reports for the API diff between the baseline version and the current one for all modules .
* reports for the API diff between the baseline version and the current one for all modules .
@ -51,6 +50,8 @@ import org.gradle.jvm.tasks.Jar;
* /
* /
public class ApiDiffPlugin implements Plugin < Project > {
public class ApiDiffPlugin implements Plugin < Project > {
private static final Logger logger = LoggerFactory . getLogger ( ApiDiffPlugin . class ) ;
public static final String TASK_NAME = "apiDiff" ;
public static final String TASK_NAME = "apiDiff" ;
private static final String BASELINE_VERSION_PROPERTY = "baselineVersion" ;
private static final String BASELINE_VERSION_PROPERTY = "baselineVersion" ;
@ -70,7 +71,11 @@ public class ApiDiffPlugin implements Plugin<Project> {
private void applyApiDiffConventions ( Project project ) {
private void applyApiDiffConventions ( Project project ) {
String baselineVersion = project . property ( BASELINE_VERSION_PROPERTY ) . toString ( ) ;
String baselineVersion = project . property ( BASELINE_VERSION_PROPERTY ) . toString ( ) ;
project . subprojects ( subProject - > createApiDiffTask ( baselineVersion , subProject ) ) ;
project . subprojects ( subProject - > {
if ( subProject . getName ( ) . startsWith ( "spring-" ) ) {
createApiDiffTask ( baselineVersion , subProject ) ;
}
} ) ;
}
}
private void createApiDiffTask ( String baselineVersion , Project project ) {
private void createApiDiffTask ( String baselineVersion , Project project ) {
@ -83,7 +88,7 @@ public class ApiDiffPlugin implements Plugin<Project> {
apiDiff . setDescription ( "Generates an API diff report with japicmp" ) ;
apiDiff . setDescription ( "Generates an API diff report with japicmp" ) ;
apiDiff . setGroup ( JavaBasePlugin . DOCUMENTATION_GROUP ) ;
apiDiff . setGroup ( JavaBasePlugin . DOCUMENTATION_GROUP ) ;
apiDiff . setOldClasspath ( project . files ( createBaselineConfiguration ( baselineVersion , project ) ) ) ;
apiDiff . setOldClasspath ( createBaselineConfiguration ( baselineVersion , project ) ) ;
TaskProvider < Jar > jar = project . getTasks ( ) . withType ( Jar . class ) . named ( "jar" ) ;
TaskProvider < Jar > jar = project . getTasks ( ) . withType ( Jar . class ) . named ( "jar" ) ;
apiDiff . setNewArchives ( project . getLayout ( ) . files ( jar . get ( ) . getArchiveFile ( ) . get ( ) . getAsFile ( ) ) ) ;
apiDiff . setNewArchives ( project . getLayout ( ) . files ( jar . get ( ) . getArchiveFile ( ) . get ( ) . getAsFile ( ) ) ) ;
apiDiff . setNewClasspath ( getRuntimeClassPath ( project ) ) ;
apiDiff . setNewClasspath ( getRuntimeClassPath ( project ) ) ;
@ -109,7 +114,16 @@ public class ApiDiffPlugin implements Plugin<Project> {
String baseline = String . join ( ":" ,
String baseline = String . join ( ":" ,
project . getGroup ( ) . toString ( ) , project . getName ( ) , baselineVersion ) ;
project . getGroup ( ) . toString ( ) , project . getName ( ) , baselineVersion ) ;
Dependency baselineDependency = project . getDependencies ( ) . create ( baseline + "@jar" ) ;
Dependency baselineDependency = project . getDependencies ( ) . create ( baseline + "@jar" ) ;
return project . getRootProject ( ) . getConfigurations ( ) . detachedConfiguration ( baselineDependency ) ;
Configuration baselineConfiguration = project . getRootProject ( ) . getConfigurations ( ) . detachedConfiguration ( baselineDependency ) ;
try {
// eagerly resolve the baseline configuration to check whether this is a new Spring module
baselineConfiguration . resolve ( ) ;
return baselineConfiguration ;
}
catch ( GradleException exception ) {
logger . warn ( "Could not resolve {} - assuming this is a new Spring module." , baseline ) ;
}
return project . getRootProject ( ) . getConfigurations ( ) . detachedConfiguration ( ) ;
}
}
private Configuration getRuntimeClassPath ( Project project ) {
private Configuration getRuntimeClassPath ( Project project ) {