Gradle leaves java process after finishing ant inv

2019-08-11 06:04发布

I am in the process of migrating to gradle one of our modules say gradle-module. That module has two dependencies that are currently build with ant say ant-module-1 and ant-module-2

In my gradle-module build.gradle i have the following entries:

task packageAntModule1(type: GradleBuild) {
    buildFile = 'antModule1.gradle'
    tasks = ['clean', 'package']
}

task packageAntModule2(type: GradleBuild) {
    buildFile = 'antModule2.gradle'
    tasks = ['clean', 'package']
}

compileJava.dependsOn(['packageAntModule1', 'packageAntModule2'])

The two files antModule1.gradle and antModule2.gradle are as simple as:

antModule1.gradle:
ant.importBuild '../ant-module1/build.xml'

antModule2.gradle:2
ant.importBuild '../ant-module2/build.xml'

I can see in the logs as part of building gradle-module that ant-module1 targets get executed and then moving to building ant-module2. However this is crashing because a temporary file created while building ant-module1 cannot be deleted. Looking at the java processes I can see a java process open by the first ant invocation which still holds my temporary file (loading some custom ant tasks)

So my question is what would be a way to tell gradle to finish off the ant JVM after finishing executing the required targets.

Any other suggestion about how to resolve my two ant dependencies would also be appreciated. Pointing to a maven repository via artifactory or nexus is not an option as our ant builds do not use ivy which is in fact the main reason we are moving to gradle

On top of this after gradle build fails the java processes started by ant are still alive and you manually have to kill them.

Thank you in advance for your inputs

UPDATE to add gradle version

$gradle -version
------------------------------------------------------------
Gradle 2.4
------------------------------------------------------------
Build time:   2015-05-05 08:09:24 UTC
Build number: none
Revision:     5c9c3bc20ca1c281ac7972643f1e2d190f2c943c

Groovy:       2.3.10
Ant:          Apache Ant(TM) version 1.9.4 compiled on April 29 2014
JVM:          1.8.0_40 (Oracle Corporation 25.40-b25)
OS:           Windows 7 6.1 amd64

标签: ant gradle
1条回答
时光不老,我们不散
2楼-- · 2019-08-11 06:37

Can you move the taskdef such that it's declared inside the ant task? This way the classloader should be discarded each time it fires.

I'm assuming that the taskdef is defined at the root level and therefore the classloader is kept in memory the whole time that the ant model is in memory.

Another workaround might be to copy the jar to a temp location which is different for packageAntModule1 and packageAntModule2.

查看更多
登录 后发表回答