From 4486da8ef3c270fe318a411ddd0d240ac1fed561 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 21 Jan 2020 12:09:17 +0000 Subject: [PATCH] Use JavaExec to invoke Ant with required dependencies on its classpath Previously, we were adding dependencies to Ant's ClassLoader within Gradle. It is suspected that this was causing sporadic loader contraint violations as types that Gradle itself uses (from Commons Compress) were then available from two different ClassLoaders. This commit reworks the Ant smoke test to use JavaExec and Ant's launcher to run the build. This allows us to make the necessary dependencies available to Ant in an isolated manner. The javac invocation within Ant is now forked to allow it to find the tools jar even when the build itself is running on a JRE. Closes gh-19839 --- .../spring-boot-smoke-test-ant/build.gradle | 22 +++++++++---------- .../spring-boot-smoke-test-ant/build.xml | 2 +- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-ant/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-ant/build.gradle index 8e7b02eb8a..0551df02a2 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-ant/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-ant/build.gradle @@ -25,6 +25,8 @@ plugins.withType(EclipsePlugin) { dependencies { antDependencies 'org.apache.ivy:ivy:2.4.0' antDependencies project(path: ':spring-boot-project:spring-boot-tools:spring-boot-antlib') + antDependencies 'org.apache.ant:ant-launcher:1.9.3' + antDependencies 'org.apache.ant:ant:1.9.3' testRepository project(path: ':spring-boot-project:spring-boot-tools:spring-boot-loader', configuration: 'mavenRepository') testRepository project(path: ':spring-boot-project:spring-boot-starters:spring-boot-starter', configuration: 'mavenRepository') @@ -44,22 +46,18 @@ task syncTestRepository(type: Sync) { } } -ant.importBuild('build.xml') { - 'ant' + it -} -ant.properties['ant-spring-boot.version'] = project.version -ant.properties['projectDir'] = project.layout.projectDirectory - -antresolve { +task antRun(type: JavaExec) { dependsOn syncTestRepository, configurations.antDependencies - doFirst { - ClassLoader antClassLoader = org.apache.tools.ant.Project.class.classLoader - configurations.antDependencies.each { antClassLoader.addURL it.toURI().toURL() } - } + classpath = configurations.antDependencies; + main = 'org.apache.tools.ant.launch.Launcher' + systemProperties = [ + 'ant-spring-boot.version' : version, + 'projectDir': project.layout.projectDirectory + ] } task test(type: Test) { - dependsOn antbuild + dependsOn antRun testClassesDirs = sourceSets.test.output.classesDirs classpath = sourceSets.test.runtimeClasspath } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-ant/build.xml b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-ant/build.xml index 1cc4fcae34..df45ef2f87 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-ant/build.xml +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-ant/build.xml @@ -29,7 +29,7 @@ - +