从Gradle构建文件中调用Ant jar目标

时间:2012-11-06 23:49:06

标签: ant gradle

如何从Gradle构建文件中调用Ant目标'jar'?我尝试过很多东西都无济于事。不能在Ant构建文件中重命名'jar'目标。我正在将基于Ant的构建系统转换为Gradle,并且第一个必需的步骤是从Gradle调用所有Ant目标。

'jar'任务是一个默认的Gradle任务,所以我覆盖/覆盖它,但是我需要调用我同名的Ant目标。

Gradle build.gradle文件:

// Prevents error "Cannot add task {taskname} as a task with that name already exists"
ant.project.addTarget('clean', new org.apache.tools.ant.Target())
ant.project.addTarget('jar', new org.apache.tools.ant.Target())
ant.project.addTarget('test', new org.apache.tools.ant.Target())
ant.project.addTarget('javadoc', new org.apache.tools.ant.Target())

ant.importBuild 'build.xml'

task jar(overwrite: true) {        
    println 'jar'
}

task clean(overwrite: true) {        
    println 'clean'
}

task test(overwrite: true) {
    println 'test'
}

和我的Ant build.xml:

<target name='jar' description='jar'>
    <echo>Called jar task in ant build</echo>
</target>

运行Gradle v1.2

------------------------------------------------------------
Gradle 1.2
------------------------------------------------------------

Gradle build time: Wednesday, September 12, 2012 10:46:02 AM UTC
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.8.4 compiled on May 22 2012
Ivy: 2.2.0
JVM: 1.6.0_25 (Sun Microsystems Inc. 20.0-b11)
OS: Linux 2.6.37.6 amd64

1 个答案:

答案 0 :(得分:0)

Gradle只在您应用Java插件时添加jar任务,您不应该为导入Ant构建的项目执行此操作。我认为您不应该从Gradle构建脚本中调用ant.project.addTarget