@@ -186,18 +186,21 @@ tasks.named('forbiddenApisInternalClusterTest').configure { forbidSleep() }
186186
187187// Set to current version by default
188188def japicmpCompareTarget = System . getProperty(" japicmp.compare.version" )
189- if (japicmpCompareTarget == null ) { /* use latest released version */
190- // Read the list from maven central.
191- // Fetch the metadata and parse the xml into Version instances, pick the latest one
189+ if (japicmpCompareTarget == null ) {
190+ // Fetch released versions from maven central, pick the latest on the same major line before current .
191+ def currentVersion = org.opensearch.gradle. Version. fromString( org.opensearch.gradle.VersionProperties . getOpenSearch())
192192 japicmpCompareTarget = new URL (' https://repo1.maven.org/maven2/org/opensearch/opensearch/maven-metadata.xml' ). openStream(). withStream { s ->
193- new XmlParser (). parse(s)
194- .versioning. versions. version
195- .collect { it. text() }. findAll { it ==~ / \d +\.\d +\.\d +/ }
196- .collect { org.opensearch.gradle.Version . fromString(it) }
197- .toSorted()
198- .last()
199- .toString()
200- }
193+ new XmlParser (). parse(s). versioning. versions. version
194+ .collect { it. text() }
195+ .findAll { it ==~ / \d +\.\d +\.\d +/ }
196+ .collect { org.opensearch.gradle.Version . fromString(it) }
197+ .findAll { it. getMajor() == currentVersion. getMajor() && it. before(currentVersion) }
198+ .toSorted()
199+ .with { it. empty ? null : it. last(). toString() }
200+ }
201+ if (japicmpCompareTarget == null ) {
202+ logger. lifecycle(" No prior released version found on the same major line. Skipping japicmp." )
203+ }
201204}
202205
203206def generateModulesList = tasks. register(" generateModulesList" ) {
@@ -512,22 +515,25 @@ tasks.named("sourcesJar").configure {
512515 }
513516}
514517
515- /* * Compares the current build against a laltest released version or the version supplied through 'japicmp.compare.version' system property */
518+ /* * Compares the current build against a latest released version or the version supplied through 'japicmp.compare.version' system property */
516519tasks. register(" japicmp" , me.champeau.gradle.japicmp.JapicmpTask ) {
517- logger. info(" Comparing public APIs from ${ version} to ${ japicmpCompareTarget} " )
518- // See please https://github.com/siom79/japicmp/issues/201
519- compatibilityChangeExcludes = [ " METHOD_ABSTRACT_NOW_DEFAULT" , " METHOD_ADDED_TO_INTERFACE" ]
520- oldClasspath. from(files(" ${ buildDir} /japicmp-target/opensearch-${ japicmpCompareTarget} .jar" ))
521- newClasspath. from(tasks. named(' jar' ))
522- onlyModified = true
523- failOnModification = true
524- ignoreMissingClasses = true
525- failOnSourceIncompatibility = true
526- annotationIncludes = [' @org.opensearch.common.annotation.PublicApi' , ' @org.opensearch.common.annotation.DeprecatedApi' ]
527- annotationExcludes = [' @org.opensearch.common.annotation.InternalApi' , ' @org.opensearch.common.annotation.ExperimentalApi' ]
528- txtOutputFile = layout. buildDirectory. file(" reports/java-compatibility/report.txt" )
529- htmlOutputFile = layout. buildDirectory. file(" reports/java-compatibility/report.html" )
530- dependsOn downloadJapicmpCompareTarget
520+ enabled = japicmpCompareTarget != null
521+ if (japicmpCompareTarget != null ) {
522+ logger. lifecycle(" Comparing public APIs from ${ version} to ${ japicmpCompareTarget} " )
523+ // See please https://github.com/siom79/japicmp/issues/201
524+ compatibilityChangeExcludes = [ " METHOD_ABSTRACT_NOW_DEFAULT" , " METHOD_ADDED_TO_INTERFACE" ]
525+ oldClasspath. from(files(" ${ buildDir} /japicmp-target/opensearch-${ japicmpCompareTarget} .jar" ))
526+ newClasspath. from(tasks. named(' jar' ))
527+ onlyModified = true
528+ failOnModification = true
529+ ignoreMissingClasses = true
530+ failOnSourceIncompatibility = true
531+ annotationIncludes = [' @org.opensearch.common.annotation.PublicApi' , ' @org.opensearch.common.annotation.DeprecatedApi' ]
532+ annotationExcludes = [' @org.opensearch.common.annotation.InternalApi' , ' @org.opensearch.common.annotation.ExperimentalApi' ]
533+ txtOutputFile = layout. buildDirectory. file(" reports/java-compatibility/report.txt" )
534+ htmlOutputFile = layout. buildDirectory. file(" reports/java-compatibility/report.html" )
535+ dependsOn downloadJapicmpCompareTarget
536+ }
531537}
532538
533539/* * If the Java API Comparison task failed, print a hint if the change should be merged from its target branch */
0 commit comments