Skip to content

Commit 4486da8

Browse files
committed
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
1 parent 62a848f commit 4486da8

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-ant/build.gradle

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ plugins.withType(EclipsePlugin) {
2525
dependencies {
2626
antDependencies 'org.apache.ivy:ivy:2.4.0'
2727
antDependencies project(path: ':spring-boot-project:spring-boot-tools:spring-boot-antlib')
28+
antDependencies 'org.apache.ant:ant-launcher:1.9.3'
29+
antDependencies 'org.apache.ant:ant:1.9.3'
2830

2931
testRepository project(path: ':spring-boot-project:spring-boot-tools:spring-boot-loader', configuration: 'mavenRepository')
3032
testRepository project(path: ':spring-boot-project:spring-boot-starters:spring-boot-starter', configuration: 'mavenRepository')
@@ -44,22 +46,18 @@ task syncTestRepository(type: Sync) {
4446
}
4547
}
4648

47-
ant.importBuild('build.xml') {
48-
'ant' + it
49-
}
50-
ant.properties['ant-spring-boot.version'] = project.version
51-
ant.properties['projectDir'] = project.layout.projectDirectory
52-
53-
antresolve {
49+
task antRun(type: JavaExec) {
5450
dependsOn syncTestRepository, configurations.antDependencies
55-
doFirst {
56-
ClassLoader antClassLoader = org.apache.tools.ant.Project.class.classLoader
57-
configurations.antDependencies.each { antClassLoader.addURL it.toURI().toURL() }
58-
}
51+
classpath = configurations.antDependencies;
52+
main = 'org.apache.tools.ant.launch.Launcher'
53+
systemProperties = [
54+
'ant-spring-boot.version' : version,
55+
'projectDir': project.layout.projectDirectory
56+
]
5957
}
6058

6159
task test(type: Test) {
62-
dependsOn antbuild
60+
dependsOn antRun
6361
testClassesDirs = sourceSets.test.output.classesDirs
6462
classpath = sourceSets.test.runtimeClasspath
6563
}

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-ant/build.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
</target>
3030

3131
<target name="compile" depends="init" description="compile">
32-
<javac srcdir="src/main/java" destdir="build/ant/classes" classpathref="compile.classpath" />
32+
<javac srcdir="src/main/java" destdir="build/ant/classes" classpathref="compile.classpath" fork="true" />
3333
</target>
3434

3535
<target name="clean" description="cleans all created files/dirs">

0 commit comments

Comments
 (0)