diff --git a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/fixtures/LocalRepositoryFixture.groovy b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/fixtures/LocalRepositoryFixture.groovy index e39d178bff2b6..99be5d62e5d97 100644 --- a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/fixtures/LocalRepositoryFixture.groovy +++ b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/fixtures/LocalRepositoryFixture.groovy @@ -17,8 +17,20 @@ class LocalRepositoryFixture extends ExternalResource{ private TemporaryFolder temporaryFolder - LocalRepositoryFixture(TemporaryFolder temporaryFolder){ - this.temporaryFolder = temporaryFolder + LocalRepositoryFixture(){ + this.temporaryFolder = new TemporaryFolder() + } + + @Override + protected void before() throws Throwable { + super.before() + temporaryFolder.before() + } + + @Override + protected void after() { + super.after() + temporaryFolder.after() } void generateJar(String group, String module, String version, String... clazzNames){ diff --git a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/BuildPluginFuncTest.groovy b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/BuildPluginFuncTest.groovy index b950fadecce78..1c64f4c9bf5d5 100644 --- a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/BuildPluginFuncTest.groovy +++ b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/BuildPluginFuncTest.groovy @@ -10,7 +10,11 @@ package org.elasticsearch.gradle.internal import org.apache.commons.io.IOUtils import org.elasticsearch.gradle.fixtures.AbstractGradleFuncTest +import org.elasticsearch.gradle.fixtures.LocalRepositoryFixture import org.gradle.testkit.runner.TaskOutcome +import org.junit.ClassRule +import org.junit.rules.TemporaryFolder +import spock.lang.Shared import java.nio.charset.StandardCharsets import java.util.zip.ZipEntry @@ -20,6 +24,10 @@ import static org.elasticsearch.gradle.fixtures.TestClasspathUtils.setupJarHellJ class BuildPluginFuncTest extends AbstractGradleFuncTest { + @Shared + @ClassRule + public LocalRepositoryFixture repository = new LocalRepositoryFixture() + def EXAMPLE_LICENSE = """\ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -120,6 +128,8 @@ class BuildPluginFuncTest extends AbstractGradleFuncTest { def "applies checks"() { given: + repository.generateJar("org.elasticsearch", "build-conventions", "unspecified", 'org.acme.CheckstyleStuff') + repository.configureBuild(buildFile) setupJarHellJar(dir('local-repo/org/elasticsearch/elasticsearch-core/current/')) file("licenses/hamcrest-core-1.3.jar.sha1").text = "42a25dc3219429f0e5d060061f71acb49bf010a0" file("licenses/hamcrest-core-LICENSE.txt").text = EXAMPLE_LICENSE diff --git a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/ElasticsearchJavaPluginFuncTest.groovy b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/ElasticsearchJavaPluginFuncTest.groovy index 5fd7aedecb268..ff329e766bfe7 100644 --- a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/ElasticsearchJavaPluginFuncTest.groovy +++ b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/ElasticsearchJavaPluginFuncTest.groovy @@ -8,24 +8,22 @@ package org.elasticsearch.gradle.internal -import org.elasticsearch.gradle.fixtures.AbstractGradleFuncTest +import org.elasticsearch.gradle.fixtures.AbstractGradleInternalPluginFuncTest +import org.gradle.api.Plugin -class ElasticsearchJavaPluginFuncTest extends AbstractGradleFuncTest { +class ElasticsearchJavaPluginFuncTest extends AbstractGradleInternalPluginFuncTest { + + Class pluginClassUnderTest = ElasticsearchJavaPlugin.class def "compatibility options are resolved from from build params minimum runtime version"() { when: - buildFile.text = """ - plugins { - id 'elasticsearch.global-build-info' - } + buildFile.text << """ import org.elasticsearch.gradle.Architecture import org.elasticsearch.gradle.internal.info.BuildParams BuildParams.init { it.setMinimumRuntimeVersion(JavaVersion.VERSION_1_10) } - apply plugin:'elasticsearch.java' - - assert compileJava.sourceCompatibility == JavaVersion.VERSION_1_10.toString() - assert compileJava.targetCompatibility == JavaVersion.VERSION_1_10.toString() + assert tasks.named('compileJava').get().sourceCompatibility == JavaVersion.VERSION_1_10.toString() + assert tasks.named('compileJava').get().targetCompatibility == JavaVersion.VERSION_1_10.toString() """ then: @@ -34,14 +32,10 @@ class ElasticsearchJavaPluginFuncTest extends AbstractGradleFuncTest { def "compile option --release is configured from targetCompatibility"() { when: - buildFile.text = """ - plugins { - id 'elasticsearch.java' - } - - compileJava.targetCompatibility = "1.10" + buildFile.text << """ + tasks.named('compileJava').get().targetCompatibility = "1.10" afterEvaluate { - assert compileJava.options.release.get() == 10 + assert tasks.named('compileJava').get().options.release.get() == 10 } """ then: diff --git a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/InternalBwcGitPluginFuncTest.groovy b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/InternalBwcGitPluginFuncTest.groovy index 756562ab02725..8a10ad587cb8b 100644 --- a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/InternalBwcGitPluginFuncTest.groovy +++ b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/InternalBwcGitPluginFuncTest.groovy @@ -14,6 +14,8 @@ import org.gradle.testkit.runner.TaskOutcome class InternalBwcGitPluginFuncTest extends AbstractGitAwareGradleFuncTest { def setup() { + // using LoggedExec is not cc compatible + configurationCacheCompatible = false internalBuild() buildFile << """ import org.elasticsearch.gradle.Version; diff --git a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/InternalDistributionBwcSetupPluginFuncTest.groovy b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/InternalDistributionBwcSetupPluginFuncTest.groovy index 2d1a6193189d7..48b2b52820c8a 100644 --- a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/InternalDistributionBwcSetupPluginFuncTest.groovy +++ b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/InternalDistributionBwcSetupPluginFuncTest.groovy @@ -22,6 +22,8 @@ import spock.lang.Unroll class InternalDistributionBwcSetupPluginFuncTest extends AbstractGitAwareGradleFuncTest { def setup() { + // used LoggedExec task is not configuration cache compatible and + configurationCacheCompatible = false internalBuild() buildFile << """ apply plugin: 'elasticsearch.internal-distribution-bwc-setup' diff --git a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/JdkDownloadPluginFuncTest.groovy b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/JdkDownloadPluginFuncTest.groovy index 63aa65fec359e..8300318fbdc16 100644 --- a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/JdkDownloadPluginFuncTest.groovy +++ b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/JdkDownloadPluginFuncTest.groovy @@ -147,6 +147,7 @@ class JdkDownloadPluginFuncTest extends AbstractGradleFuncTest { plugins { id 'elasticsearch.jdk-download' } + import org.elasticsearch.gradle.internal.Jdk apply plugin: 'base' apply plugin: 'elasticsearch.jdk-download' @@ -158,11 +159,18 @@ class JdkDownloadPluginFuncTest extends AbstractGradleFuncTest { architecture = "x64" } } - - tasks.register("getJdk") { + + tasks.register("getJdk", PrintJdk) { dependsOn jdks.myJdk - doLast { - println "JDK HOME: " + jdks.myJdk + jdkPath = jdks.myJdk.getPath() + } + + class PrintJdk extends DefaultTask { + @Input + String jdkPath + + @TaskAction void print() { + println "JDK HOME: " + jdkPath } } """ diff --git a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/PublishPluginFuncTest.groovy b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/PublishPluginFuncTest.groovy index 7f7922c0623d3..12d0ce41e105e 100644 --- a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/PublishPluginFuncTest.groovy +++ b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/PublishPluginFuncTest.groovy @@ -250,6 +250,8 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest { def "generates artifacts for shadowed elasticsearch plugin"() { given: + // we use the esplugin plugin in this test that is not configuration cache compatible yet + configurationCacheCompatible = false file('license.txt') << "License file" file('notice.txt') << "Notice file" buildFile << """ @@ -334,6 +336,8 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest { def "generates pom for elasticsearch plugin"() { given: + // we use the esplugin plugin in this test that is not configuration cache compatible yet + configurationCacheCompatible = false file('license.txt') << "License file" file('notice.txt') << "Notice file" buildFile << """ diff --git a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/distibution/ElasticsearchDistributionPluginFuncTest.groovy b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/distibution/ElasticsearchDistributionPluginFuncTest.groovy index f3baf5910fca9..8686ad3df79ae 100644 --- a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/distibution/ElasticsearchDistributionPluginFuncTest.groovy +++ b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/distibution/ElasticsearchDistributionPluginFuncTest.groovy @@ -15,6 +15,8 @@ class ElasticsearchDistributionPluginFuncTest extends AbstractGradleFuncTest { def "copied modules are resolved from explodedBundleZip"() { given: + // we use the esplugin plugin in this test that is not configuration cache compatible yet + configurationCacheCompatible = false moduleSubProject() buildFile << """plugins { diff --git a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/precommit/LicenseHeadersPrecommitPluginFuncTest.groovy b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/precommit/LicenseHeadersPrecommitPluginFuncTest.groovy index 3ad8999f838e6..fed667b014c23 100644 --- a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/precommit/LicenseHeadersPrecommitPluginFuncTest.groovy +++ b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/precommit/LicenseHeadersPrecommitPluginFuncTest.groovy @@ -18,7 +18,6 @@ class LicenseHeadersPrecommitPluginFuncTest extends AbstractGradleInternalPlugin Class pluginClassUnderTest = LicenseHeadersPrecommitPlugin.class def setup() { - configurationCacheCompatible = true buildFile << """ apply plugin:'java' """ diff --git a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/precommit/TestingConventionsPrecommitPluginFuncTest.groovy b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/precommit/TestingConventionsPrecommitPluginFuncTest.groovy index 19d5296b8defe..af5462630f55d 100644 --- a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/precommit/TestingConventionsPrecommitPluginFuncTest.groovy +++ b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/precommit/TestingConventionsPrecommitPluginFuncTest.groovy @@ -24,13 +24,9 @@ class TestingConventionsPrecommitPluginFuncTest extends AbstractGradleInternalPl Class pluginClassUnderTest = TestingConventionsPrecommitPlugin.class - @ClassRule - @Shared - public TemporaryFolder repoFolder = new TemporaryFolder() - @Shared @ClassRule - public LocalRepositoryFixture repository = new LocalRepositoryFixture(repoFolder) + public LocalRepositoryFixture repository = new LocalRepositoryFixture() def setupSpec() { repository.generateJar('org.apache.lucene', 'tests.util', "1.0", @@ -45,7 +41,6 @@ class TestingConventionsPrecommitPluginFuncTest extends AbstractGradleInternalPl } def setup() { - configurationCacheCompatible = true repository.configureBuild(buildFile) } diff --git a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/precommit/ThirdPartyAuditTaskFuncTest.groovy b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/precommit/ThirdPartyAuditTaskFuncTest.groovy index 94100d499c236..11b32e108a54b 100644 --- a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/precommit/ThirdPartyAuditTaskFuncTest.groovy +++ b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/precommit/ThirdPartyAuditTaskFuncTest.groovy @@ -15,25 +15,24 @@ import net.bytebuddy.dynamic.DynamicType import net.bytebuddy.implementation.FixedValue import org.apache.logging.log4j.LogManager import org.elasticsearch.gradle.fixtures.AbstractGradleFuncTest +import org.elasticsearch.gradle.fixtures.AbstractGradleInternalPluginFuncTest +import org.elasticsearch.gradle.internal.conventions.precommit.LicenseHeadersPrecommitPlugin +import org.elasticsearch.gradle.internal.conventions.precommit.PrecommitPlugin import org.gradle.testkit.runner.TaskOutcome import static org.elasticsearch.gradle.fixtures.TestClasspathUtils.setupJarJdkClasspath -class ThirdPartyAuditTaskFuncTest extends AbstractGradleFuncTest { +class ThirdPartyAuditTaskFuncTest extends AbstractGradleInternalPluginFuncTest { + + Class pluginClassUnderTest = ThirdPartyAuditPrecommitPlugin.class def setup() { buildFile << """ import org.elasticsearch.gradle.internal.precommit.ThirdPartyAuditPrecommitPlugin import org.elasticsearch.gradle.internal.precommit.ThirdPartyAuditTask - plugins { - id 'java' - // bring in build-tools onto the classpath - id 'elasticsearch.global-build-info' - } - - plugins.apply(ThirdPartyAuditPrecommitPlugin) + apply plugin:'java' group = 'org.elasticsearch' version = 'current' @@ -48,7 +47,7 @@ class ThirdPartyAuditTaskFuncTest extends AbstractGradleFuncTest { mavenCentral() } - tasks.register("thirdPartyCheck", ThirdPartyAuditTask) { + tasks.named("thirdPartyAudit").configure { signatureFile = file('signature-file.txt') } """ @@ -58,6 +57,7 @@ class ThirdPartyAuditTaskFuncTest extends AbstractGradleFuncTest { given: def group = "org.elasticsearch.gradle" generateDummyJars(group) + setupJarJdkClasspath(dir('local-repo/org/elasticsearch/elasticsearch-core/current/')) file('signature-file.txt') << "@defaultMessage non-public internal runtime class" buildFile << """ @@ -68,9 +68,9 @@ class ThirdPartyAuditTaskFuncTest extends AbstractGradleFuncTest { } """ when: - def result = gradleRunner("thirdPartyCheck").build() + def result = gradleRunner("thirdPartyAudit").build() then: - result.task(":thirdPartyCheck").outcome == TaskOutcome.NO_SOURCE + result.task(":thirdPartyAudit").outcome == TaskOutcome.NO_SOURCE assertNoDeprecationWarning(result) } @@ -91,9 +91,9 @@ class ThirdPartyAuditTaskFuncTest extends AbstractGradleFuncTest { } """ when: - def result = gradleRunner(":thirdPartyCheck").buildAndFail() + def result = gradleRunner(":thirdPartyAudit").buildAndFail() then: - result.task(":thirdPartyCheck").outcome == TaskOutcome.FAILED + result.task(":thirdPartyAudit").outcome == TaskOutcome.FAILED def output = normalized(result.getOutput()) assertOutputContains(output, """\ @@ -127,9 +127,9 @@ class ThirdPartyAuditTaskFuncTest extends AbstractGradleFuncTest { } """ when: - def result = gradleRunner(":thirdPartyCheck").buildAndFail() + def result = gradleRunner(":thirdPartyAudit").buildAndFail() then: - result.task(":thirdPartyCheck").outcome == TaskOutcome.FAILED + result.task(":thirdPartyAudit").outcome == TaskOutcome.FAILED def output = normalized(result.getOutput()) assertOutputContains(output, """\ @@ -163,9 +163,9 @@ class ThirdPartyAuditTaskFuncTest extends AbstractGradleFuncTest { } """ when: - def result = gradleRunner(":thirdPartyCheck").buildAndFail() + def result = gradleRunner(":thirdPartyAudit").buildAndFail() then: - result.task(":thirdPartyCheck").outcome == TaskOutcome.FAILED + result.task(":thirdPartyAudit").outcome == TaskOutcome.FAILED def output = normalized(result.getOutput()) assertOutputContains(output, """\ @@ -174,7 +174,7 @@ class ThirdPartyAuditTaskFuncTest extends AbstractGradleFuncTest { """.stripIndent()) assertOutputContains(output, """\ * What went wrong: - Execution failed for task ':thirdPartyCheck'. + Execution failed for task ':thirdPartyAudit'. > Audit of third party dependencies failed: Jar Hell with the JDK: * diff --git a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/test/rest/InternalYamlRestTestPluginFuncTest.groovy b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/test/rest/InternalYamlRestTestPluginFuncTest.groovy index ad8aad6f01baa..e70be2b4de4df 100644 --- a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/test/rest/InternalYamlRestTestPluginFuncTest.groovy +++ b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/test/rest/InternalYamlRestTestPluginFuncTest.groovy @@ -19,6 +19,8 @@ class InternalYamlRestTestPluginFuncTest extends AbstractRestResourcesFuncTest { def "yamlRestTest does nothing when there are no tests"() { given: + // RestIntegTestTask not cc compatible due to + configurationCacheCompatible = false buildFile << """ plugins { id 'elasticsearch.internal-yaml-rest-test' @@ -36,6 +38,8 @@ class InternalYamlRestTestPluginFuncTest extends AbstractRestResourcesFuncTest { def "yamlRestTest executes and copies api and tests to correct source set"() { given: + // RestIntegTestTask not cc compatible due to + configurationCacheCompatible = false internalBuild() buildFile << """ apply plugin: 'elasticsearch.internal-yaml-rest-test' diff --git a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/test/rest/RestResourcesPluginFuncTest.groovy b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/test/rest/RestResourcesPluginFuncTest.groovy index 6db4a437a0296..e083dc6ff56d5 100644 --- a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/test/rest/RestResourcesPluginFuncTest.groovy +++ b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/test/rest/RestResourcesPluginFuncTest.groovy @@ -170,7 +170,7 @@ class RestResourcesPluginFuncTest extends AbstractRestResourcesFuncTest { file("/build/restResources/yamlTests/rest-api-spec/test/" + coreTest).getText("UTF-8") == "replacedWithValue" when: - result = gradleRunner("copyRestApiSpecsTask").build() + result = gradleRunner("copyRestApiSpecsTask", '--stacktrace').build() then: result.task(':copyRestApiSpecsTask').outcome == TaskOutcome.UP_TO_DATE diff --git a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/test/rest/YamlRestCompatTestPluginFuncTest.groovy b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/test/rest/YamlRestCompatTestPluginFuncTest.groovy index 35079b3d29848..acf86ddff73ff 100644 --- a/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/test/rest/YamlRestCompatTestPluginFuncTest.groovy +++ b/build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/test/rest/YamlRestCompatTestPluginFuncTest.groovy @@ -28,6 +28,12 @@ class YamlRestCompatTestPluginFuncTest extends AbstractRestResourcesFuncTest { def READER = MAPPER.readerFor(ObjectNode.class) def WRITER = MAPPER.writerFor(ObjectNode.class) + def setup() { + // not cc compatible due to: + // 1. TestClustersPlugin not cc compatible due to listener registration + // 2. RestIntegTestTask not cc compatible due to + configurationCacheCompatible = false + } def "yamlRestTestVxCompatTest does nothing when there are no tests"() { given: subProject(":distribution:bwc:maintenance") << """ diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchJavadocPlugin.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchJavadocPlugin.java index 1c6831feab7b0..b7d88ce381437 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchJavadocPlugin.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchJavadocPlugin.java @@ -32,11 +32,9 @@ // other packages (e.g org.elasticsearch.client) will point to server rather than // their own artifacts. public class ElasticsearchJavadocPlugin implements Plugin { - private Project project; @Override public void apply(Project project) { - this.project = project; // ignore missing javadocs project.getTasks().withType(Javadoc.class).configureEach(javadoc -> { // the -quiet here is because of a bug in gradle, in that adding a string option @@ -57,7 +55,7 @@ public void execute(Task task) { }); // Relying on configurations introduced by the java plugin - this.project.getPlugins().withType(JavaPlugin.class, javaPlugin -> project.afterEvaluate(project1 -> { + project.getPlugins().withType(JavaPlugin.class, javaPlugin -> project.afterEvaluate(project1 -> { var withShadowPlugin = project1.getPlugins().hasPlugin(ShadowPlugin.class); var compileClasspath = project.getConfigurations().getByName("compileClasspath"); @@ -67,25 +65,25 @@ public void execute(Task task) { var nonShadowedCompileClasspath = compileClasspath.copyRecursive( dependency -> shadowedDependencies.contains(dependency) == false ); - configureJavadocForConfiguration(false, nonShadowedCompileClasspath); - configureJavadocForConfiguration(true, shadowConfiguration); + configureJavadocForConfiguration(project, false, nonShadowedCompileClasspath); + configureJavadocForConfiguration(project, true, shadowConfiguration); } else { - configureJavadocForConfiguration(false, compileClasspath); + configureJavadocForConfiguration(project, false, compileClasspath); } })); } - private void configureJavadocForConfiguration(boolean shadow, Configuration configuration) { + private void configureJavadocForConfiguration(Project project, boolean shadow, Configuration configuration) { configuration.getAllDependencies() .stream() .sorted(Comparator.comparing(Dependency::getGroup)) .filter(d -> d instanceof ProjectDependency) .map(d -> (ProjectDependency) d) .filter(p -> p.getDependencyProject() != null) - .forEach(projectDependency -> configureDependency(shadow, projectDependency)); + .forEach(projectDependency -> configureDependency(project, shadow, projectDependency)); } - private void configureDependency(boolean shadowed, ProjectDependency dep) { + private void configureDependency(Project project, boolean shadowed, ProjectDependency dep) { var upstreamProject = dep.getDependencyProject(); if (shadowed) { /* diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/CheckstylePrecommitPlugin.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/CheckstylePrecommitPlugin.java index 6f288e70a604b..6488f0d0dd30b 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/CheckstylePrecommitPlugin.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/CheckstylePrecommitPlugin.java @@ -86,9 +86,11 @@ public void execute(Task task) { DependencyHandler dependencies = project.getDependencies(); String checkstyleVersion = VersionProperties.getVersions().get("checkstyle"); - Provider dependencyProvider = project.provider(() -> "org.elasticsearch:build-conventions:" + project.getVersion()); + Provider conventionsDependencyProvider = project.provider( + () -> "org.elasticsearch:build-conventions:" + project.getVersion() + ); dependencies.add("checkstyle", "com.puppycrawl.tools:checkstyle:" + checkstyleVersion); - dependencies.addProvider("checkstyle", dependencyProvider, dep -> dep.setTransitive(false)); + dependencies.addProvider("checkstyle", conventionsDependencyProvider, dep -> dep.setTransitive(false)); project.getTasks().withType(Checkstyle.class).configureEach(t -> { t.dependsOn(copyCheckstyleConf); diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/ThirdPartyAuditPrecommitPlugin.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/ThirdPartyAuditPrecommitPlugin.java index 99672c559da5e..0e2631cd7d8c5 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/ThirdPartyAuditPrecommitPlugin.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/ThirdPartyAuditPrecommitPlugin.java @@ -55,7 +55,7 @@ public TaskProvider createTask(Project project) { Configuration compileOnly = project.getConfigurations() .getByName(CompileOnlyResolvePlugin.RESOLVEABLE_COMPILE_ONLY_CONFIGURATION_NAME); t.setClasspath(runtimeConfiguration.plus(compileOnly)); - t.setJarsToScan(runtimeConfiguration.fileCollection(dep -> { + t.getJarsToScan().from(runtimeConfiguration.fileCollection(dep -> { // These are SelfResolvingDependency, and some of them backed by file collections, like the Gradle API files, // or dependencies added as `files(...)`, we can't be sure if those are third party or not. // err on the side of scanning these to make sure we don't miss anything @@ -65,8 +65,8 @@ public TaskProvider createTask(Project project) { t.setJavaHome(Jvm.current().getJavaHome().getPath()); t.getTargetCompatibility().set(project.provider(BuildParams::getRuntimeJavaVersion)); t.setSignatureFile(resourcesDir.resolve("forbidden/third-party-audit.txt").toFile()); - t.setJdkJarHellClasspath(jdkJarHellConfig); - t.setForbiddenAPIsClasspath(project.getConfigurations().getByName("forbiddenApisCliJar").plus(compileOnly)); + t.getJdkJarHellClasspath().from(jdkJarHellConfig); + t.getForbiddenAPIsClasspath().from(project.getConfigurations().getByName("forbiddenApisCliJar").plus(compileOnly)); }); return audit; } diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/ThirdPartyAuditTask.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/ThirdPartyAuditTask.java index 31cd17f6449a0..229184b05af6e 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/ThirdPartyAuditTask.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/ThirdPartyAuditTask.java @@ -14,6 +14,7 @@ import org.gradle.api.DefaultTask; import org.gradle.api.JavaVersion; import org.gradle.api.file.ArchiveOperations; +import org.gradle.api.file.ConfigurableFileCollection; import org.gradle.api.file.FileCollection; import org.gradle.api.file.FileSystemOperations; import org.gradle.api.file.FileTree; @@ -55,7 +56,7 @@ import javax.inject.Inject; @CacheableTask -public class ThirdPartyAuditTask extends DefaultTask { +public abstract class ThirdPartyAuditTask extends DefaultTask { private static final Pattern MISSING_CLASS_PATTERN = Pattern.compile( "WARNING: Class '(.*)' cannot be loaded \\(.*\\)\\. Please fix the classpath!" @@ -80,8 +81,6 @@ public class ThirdPartyAuditTask extends DefaultTask { private String javaHome; - private FileCollection jdkJarHellClasspath; - private final Property targetCompatibility; private final ArchiveOperations archiveOperations; @@ -94,10 +93,6 @@ public class ThirdPartyAuditTask extends DefaultTask { private FileCollection classpath; - private FileCollection jarsToScan; - - private FileCollection forbiddenApisClasspath; - @Inject public ThirdPartyAuditTask( ArchiveOperations archiveOperations, @@ -120,13 +115,7 @@ public Property getTargetCompatibility() { @InputFiles @PathSensitive(PathSensitivity.NAME_ONLY) - public FileCollection getForbiddenAPIsClasspath() { - return forbiddenApisClasspath; - } - - public void setForbiddenAPIsClasspath(FileCollection forbiddenApisClasspath) { - this.forbiddenApisClasspath = forbiddenApisClasspath; - } + public abstract ConfigurableFileCollection getForbiddenAPIsClasspath(); @InputFile @PathSensitive(PathSensitivity.NONE) @@ -161,13 +150,7 @@ public File getSuccessMarker() { // We use compile classpath normalization here because class implementation changes are irrelevant for the purposes of jdk jar hell. // We only care about the runtime classpath ABI here. @CompileClasspath - public FileCollection getJdkJarHellClasspath() { - return jdkJarHellClasspath.filter(File::exists); - } - - public void setJdkJarHellClasspath(FileCollection jdkJarHellClasspath) { - this.jdkJarHellClasspath = jdkJarHellClasspath; - } + abstract ConfigurableFileCollection getJdkJarHellClasspath(); public void ignoreMissingClasses(String... classesOrPackages) { if (classesOrPackages.length == 0) { @@ -207,13 +190,11 @@ public Set getMissingClassExcludes() { @Classpath @SkipWhenEmpty - public FileCollection getJarsToScan() { - return jarsToScan; - } + public abstract ConfigurableFileCollection getJarsToScan(); @TaskAction public void runThirdPartyAudit() throws IOException { - Set jars = jarsToScan.getFiles(); + Set jars = getJarsToScan().getFiles(); extractJars(jars, getJarExpandDir()); final String forbiddenApisOutput = runForbiddenAPIsCli(); final Set missingClasses = new TreeSet<>(); @@ -357,7 +338,7 @@ private String runForbiddenAPIsCli() throws IOException { if (javaHome != null) { spec.setExecutable(javaHome + "/bin/java"); } - spec.classpath(forbiddenApisClasspath, classpath); + spec.classpath(getForbiddenAPIsClasspath(), classpath); spec.jvmArgs("-Xmx1g"); spec.getMainClass().set("de.thetaphi.forbiddenapis.cli.CliMain"); spec.args("-f", getSignatureFile().getAbsolutePath(), "-d", getJarExpandDir(), "--allowmissingclasses"); @@ -383,8 +364,7 @@ private String runForbiddenAPIsCli() throws IOException { private Set runJdkJarHellCheck() throws IOException { ByteArrayOutputStream standardOut = new ByteArrayOutputStream(); ExecResult execResult = execOperations.javaexec(spec -> { - spec.classpath(jdkJarHellClasspath, classpath); - + spec.classpath(getJdkJarHellClasspath(), classpath); spec.getMainClass().set(JDK_JAR_HELL_MAIN_CLASS); spec.args(getJarExpandDir()); spec.setIgnoreExitValue(true); @@ -407,7 +387,4 @@ public void setClasspath(FileCollection classpath) { this.classpath = classpath; } - public void setJarsToScan(FileCollection jarsToScan) { - this.jarsToScan = jarsToScan; - } } diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/CopyRestApiTask.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/CopyRestApiTask.java index 5c00e0428c9b7..1fbc367804ed4 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/CopyRestApiTask.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/CopyRestApiTask.java @@ -7,6 +7,7 @@ */ package org.elasticsearch.gradle.internal.test.rest; +import org.elasticsearch.gradle.internal.util.SerializableFunction; import org.gradle.api.DefaultTask; import org.gradle.api.file.DirectoryProperty; import org.gradle.api.file.FileCollection; @@ -29,7 +30,6 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; -import java.util.function.Function; import java.util.stream.Collectors; import javax.inject.Inject; @@ -54,8 +54,8 @@ public class CopyRestApiTask extends DefaultTask { private boolean skipHasRestTestCheck; private FileCollection config; private FileCollection additionalConfig; - private Function configToFileTree = FileCollection::getAsFileTree; - private Function additionalConfigToFileTree = FileCollection::getAsFileTree; + private SerializableFunction configToFileTree = FileCollection::getAsFileTree; + private SerializableFunction additionalConfigToFileTree = FileCollection::getAsFileTree; private final PatternFilterable patternSet; private final ProjectLayout projectLayout; @@ -176,11 +176,11 @@ public void setAdditionalConfig(FileCollection additionalConfig) { this.additionalConfig = additionalConfig; } - public void setConfigToFileTree(Function configToFileTree) { + public void setConfigToFileTree(SerializableFunction configToFileTree) { this.configToFileTree = configToFileTree; } - public void setAdditionalConfigToFileTree(Function additionalConfigToFileTree) { + public void setAdditionalConfigToFileTree(SerializableFunction additionalConfigToFileTree) { this.additionalConfigToFileTree = additionalConfigToFileTree; } diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/CopyRestTestsTask.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/CopyRestTestsTask.java index 5cc68f8e73d45..9359272b29610 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/CopyRestTestsTask.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/CopyRestTestsTask.java @@ -8,6 +8,7 @@ package org.elasticsearch.gradle.internal.test.rest; import org.apache.tools.ant.filters.ReplaceTokens; +import org.elasticsearch.gradle.internal.util.SerializableFunction; import org.gradle.api.DefaultTask; import org.gradle.api.file.DirectoryProperty; import org.gradle.api.file.FileCollection; @@ -29,7 +30,6 @@ import java.io.File; import java.util.Map; -import java.util.function.Function; import java.util.stream.Collectors; import javax.inject.Inject; @@ -53,9 +53,9 @@ public class CopyRestTestsTask extends DefaultTask { private FileCollection coreConfig; private FileCollection xpackConfig; private FileCollection additionalConfig; - private Function coreConfigToFileTree = FileCollection::getAsFileTree; - private Function xpackConfigToFileTree = FileCollection::getAsFileTree; - private Function additionalConfigToFileTree = FileCollection::getAsFileTree; + private SerializableFunction coreConfigToFileTree = FileCollection::getAsFileTree; + private SerializableFunction xpackConfigToFileTree = FileCollection::getAsFileTree; + private SerializableFunction additionalConfigToFileTree = FileCollection::getAsFileTree; private final PatternFilterable corePatternSet; private final PatternFilterable xpackPatternSet; @@ -183,15 +183,15 @@ public void setAdditionalConfig(FileCollection additionalConfig) { this.additionalConfig = additionalConfig; } - public void setCoreConfigToFileTree(Function coreConfigToFileTree) { + public void setCoreConfigToFileTree(SerializableFunction coreConfigToFileTree) { this.coreConfigToFileTree = coreConfigToFileTree; } - public void setXpackConfigToFileTree(Function xpackConfigToFileTree) { + public void setXpackConfigToFileTree(SerializableFunction xpackConfigToFileTree) { this.xpackConfigToFileTree = xpackConfigToFileTree; } - public void setAdditionalConfigToFileTree(Function additionalConfigToFileTree) { + public void setAdditionalConfigToFileTree(SerializableFunction additionalConfigToFileTree) { this.additionalConfigToFileTree = additionalConfigToFileTree; } diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/util/SerializableFunction.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/util/SerializableFunction.java new file mode 100644 index 0000000000000..1f2842ed396d2 --- /dev/null +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/util/SerializableFunction.java @@ -0,0 +1,20 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +package org.elasticsearch.gradle.internal.util; + +import java.io.Serializable; +import java.util.function.Function; + +/** + * A functional interface that extends Function but also Serializable. + * + * Gradle configuration cache requires fields that represent a lambda to be serializable. + * */ +@FunctionalInterface +public interface SerializableFunction extends Function, Serializable {} diff --git a/build-tools/src/integTest/groovy/org/elasticsearch/gradle/TestClustersPluginFuncTest.groovy b/build-tools/src/integTest/groovy/org/elasticsearch/gradle/TestClustersPluginFuncTest.groovy index 169ea6334c9fd..5287d4a932587 100644 --- a/build-tools/src/integTest/groovy/org/elasticsearch/gradle/TestClustersPluginFuncTest.groovy +++ b/build-tools/src/integTest/groovy/org/elasticsearch/gradle/TestClustersPluginFuncTest.groovy @@ -25,6 +25,8 @@ import static org.elasticsearch.gradle.fixtures.DistributionDownloadFixture.with class TestClustersPluginFuncTest extends AbstractGradleFuncTest { def setup() { + // TestClusterPlugin with adding task listeners is not cc compatible + configurationCacheCompatible = false buildFile << """ import org.elasticsearch.gradle.testclusters.TestClustersAware import org.elasticsearch.gradle.testclusters.ElasticsearchCluster diff --git a/build-tools/src/integTest/groovy/org/elasticsearch/gradle/plugin/PluginBuildPluginFuncTest.groovy b/build-tools/src/integTest/groovy/org/elasticsearch/gradle/plugin/PluginBuildPluginFuncTest.groovy index dc0d266688f4b..d486e109a9307 100644 --- a/build-tools/src/integTest/groovy/org/elasticsearch/gradle/plugin/PluginBuildPluginFuncTest.groovy +++ b/build-tools/src/integTest/groovy/org/elasticsearch/gradle/plugin/PluginBuildPluginFuncTest.groovy @@ -18,6 +18,11 @@ import java.util.stream.Collectors class PluginBuildPluginFuncTest extends AbstractGradleFuncTest { + def setup() { + // underlaying TestClusterPlugin and StandaloneRestIntegTestTask are not cc compatible + configurationCacheCompatible = false + } + def "can assemble plugin via #taskName"() { given: buildFile << """plugins { diff --git a/build-tools/src/integTest/groovy/org/elasticsearch/gradle/reaper/ReaperPluginFuncTest.groovy b/build-tools/src/integTest/groovy/org/elasticsearch/gradle/reaper/ReaperPluginFuncTest.groovy index 0355eb43eb46d..8cae82cccdf43 100644 --- a/build-tools/src/integTest/groovy/org/elasticsearch/gradle/reaper/ReaperPluginFuncTest.groovy +++ b/build-tools/src/integTest/groovy/org/elasticsearch/gradle/reaper/ReaperPluginFuncTest.groovy @@ -23,9 +23,10 @@ class ReaperPluginFuncTest extends AbstractGradleFuncTest { import org.elasticsearch.gradle.ReaperPlugin; import org.elasticsearch.gradle.util.GradleUtils; + def serviceProvider = GradleUtils.getBuildService(project.getGradle().getSharedServices(), ReaperPlugin.REAPER_SERVICE_NAME); + tasks.register("launchReaper") { doLast { - def serviceProvider = GradleUtils.getBuildService(project.getGradle().getSharedServices(), ReaperPlugin.REAPER_SERVICE_NAME); def reaper = serviceProvider.get() reaper.registerCommand('test', 'true') reaper.unregister('test') diff --git a/build-tools/src/integTest/groovy/org/elasticsearch/gradle/test/JavaRestTestPluginFuncTest.groovy b/build-tools/src/integTest/groovy/org/elasticsearch/gradle/test/JavaRestTestPluginFuncTest.groovy index 09c078b490f48..2d6d122663da3 100644 --- a/build-tools/src/integTest/groovy/org/elasticsearch/gradle/test/JavaRestTestPluginFuncTest.groovy +++ b/build-tools/src/integTest/groovy/org/elasticsearch/gradle/test/JavaRestTestPluginFuncTest.groovy @@ -14,6 +14,11 @@ import org.gradle.testkit.runner.TaskOutcome class JavaRestTestPluginFuncTest extends AbstractGradleFuncTest { + def setup() { + // underlaying TestClusterPlugin and StandaloneRestIntegTestTask are not cc compatible + configurationCacheCompatible = false + } + def "declares default dependencies"() { given: buildFile << """ diff --git a/build-tools/src/integTest/groovy/org/elasticsearch/gradle/test/YamlRestTestPluginFuncTest.groovy b/build-tools/src/integTest/groovy/org/elasticsearch/gradle/test/YamlRestTestPluginFuncTest.groovy index 7ff2b4f61b913..83c215ceea42d 100644 --- a/build-tools/src/integTest/groovy/org/elasticsearch/gradle/test/YamlRestTestPluginFuncTest.groovy +++ b/build-tools/src/integTest/groovy/org/elasticsearch/gradle/test/YamlRestTestPluginFuncTest.groovy @@ -14,6 +14,11 @@ import org.gradle.testkit.runner.TaskOutcome class YamlRestTestPluginFuncTest extends AbstractGradleFuncTest { + def setup() { + // underlaying TestClusterPlugin and StandaloneRestIntegTestTask are not cc compatible + configurationCacheCompatible = false + } + def "declares default dependencies"() { given: buildFile << """ diff --git a/build-tools/src/testFixtures/groovy/org/elasticsearch/gradle/fixtures/AbstractGradleFuncTest.groovy b/build-tools/src/testFixtures/groovy/org/elasticsearch/gradle/fixtures/AbstractGradleFuncTest.groovy index 755c866dafe8c..9fbfe498c61bf 100644 --- a/build-tools/src/testFixtures/groovy/org/elasticsearch/gradle/fixtures/AbstractGradleFuncTest.groovy +++ b/build-tools/src/testFixtures/groovy/org/elasticsearch/gradle/fixtures/AbstractGradleFuncTest.groovy @@ -34,7 +34,7 @@ abstract class AbstractGradleFuncTest extends Specification { File propertiesFile File projectDir - boolean configurationCacheCompatible = false + boolean configurationCacheCompatible = true def setup() { projectDir = testProjectDir.root