[英]When trying to run a simple ant script from gradle, I am getting “srcdir does not exist”
I am trying to run a simple bare minimum ant script from gradle. 我正在尝试从gradle运行一个简单的最小蚂蚁脚本。 My build.gradle only has the ant import statement
我的build.gradle只有ant import语句
ant.importBuild 'build.xml'
I have my ant build.xml as below. 我的蚂蚁build.xml如下。 Note that this works fine when I use ant compile.
请注意,当我使用ant编译时,这可以正常工作。
<?xml version="1.0"?>
<project name="SampleProject" default="antCompile" basedir="SampleProject">
<target name="antCompile">
<mkdir dir="build/classes" />
<javac srcdir="src" destdir="build/classes" />
</target>
<target name="compress" depends="antCompile">
<mkdir dir="build/jar" />
<jar destfile="build/jar/SampleProject.jar" basedir="build/classes" />
</target>
</project>
Butwhen I try to run the antCompile target using the following in command prompt. 但是,当我尝试在命令提示符下使用以下命令运行antCompile目标时。
gradle antCompile
I get the "srcdir doesnot exist" exception. 我收到“ srcdir不存在”异常。
However if I modify the build.xml to the following: 但是,如果我将build.xml修改为以下内容:
<?xml version="1.0"?>
<project name="SampleProject" default="antCompile" basedir=".">
<target name="antCompile">
<mkdir dir="SampleProject/build/classes" />
<javac includeAntRuntime="false" srcdir="SampleProject/src" destdir="SampleProject/build/classes" />
</target>
<target name="compress" depends="antCompile">
<mkdir dir="SampleProject/build/jar" />
<jar destfile="SampleProject/build/jar/SampleProject.jar" basedir="SampleProject/build/classes" />
</target>
</project>
I am able to run the script successfully from gradle. 我可以从gradle成功运行脚本。 Note that in both cases compiling using the ant tool works.
请注意,在两种情况下,使用ant工具进行编译均有效。
I am not able to identify why my first approach doesn't work when running through gradle. 我无法确定为什么我的第一种方法在通过gradle运行时不起作用。 Any help would be appreciated.
任何帮助,将不胜感激。
Seems to be a limitation of org/gradle/api/internal/project/DefaultAntBuilder.java
似乎是
org/gradle/api/internal/project/DefaultAntBuilder.java
in gradle-core-xx.jar 在gradle-core-xx.jar中
public void importBuild(Object antBuildFile, Transformer<? extends String, ? super String> taskNamer) {
File file = this.gradleProject.file(antBuildFile);
File baseDir = file.getParentFile();
Set existingAntTargets = new HashSet(getAntProject().getTargets().keySet());
File oldBaseDir = getAntProject().getBaseDir();
getAntProject().setBaseDir(baseDir);
means the basedir is set to directory containing the antscript not to the value of basedir attribute of imported ant file. 表示basedir设置为包含上标的目录,而不是导入的ant文件的basedir属性的值。
-- EDIT -- -编辑-
Found an open issue on gradle.org 在gradle.org上发现了一个未解决的问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.