Ant to Gradle,javaCompile 任务的问题



我有以下蚂蚁任务:

<javac 
srcdir="${mypackage.code.src.java}"
source="1.8"
target="1.8" 
destdir="${mypackage.build.output.}"     
deprecation="on" 
debug="true" 
>
<classpath path="${jboss.common.lib.}/hibernate-annotations-3.5.0-Final.jar" />
<classpath path="${jboss.common.lib.}/jboss-ejb3-common.jar" />
<classpath path="${jboss.common.lib.}/scheduler-plugin.jar" />
<classpath path="${jboss.common.lib.}/servlet-api.jar" />
<classpath>
<path>
<fileset dir="${myotherpackage.lib.thirdparty.}">
<include name="jboss-5.1.0.GA/ejb3-persistence.jar" />
<include name="jboss-5.1.0.GA/hibernate-core-4.2.1.final.jar"/>
<include name="jboss-5.1.0.GA/jboss-javaee.jar" />   
<include name="jboss-5.1.0.GA/jboss-j2se.jar"/>
<include name="jboss-5.1.0.GA/jsp-api.jar"/>
</fileset>
<fileset dir="${jboss.server.myotherpackage.lib.}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${jboss.server.myotherpackageear.}" >
<include name="**/*.jar"/>
</fileset>
<fileset dir="${mypackage.code.src.www}/WEB-INF/lib" >
<include name="**/*.*" />
</fileset>
</path>
</classpath>
</javac>

我正在尝试将其转换为 gradle,到目前为止,我有以下任务:

task doCompile(type: JavaCompile) {
classpath = sourceSets.mySourceSet.output
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
destinationDir = file("$mypackage_build_output")
source = file("$mypackage_code_src_java")
}

还要按如下方式定义我的源代码集:

sourceSets {
jt3SourceSet {
java {
compileClasspath += files("${jboss_common_lib}/hibernate-annotations-3.5.0-Final.jar")
compileClasspath += files("${jboss_common_lib}/jboss-ejb3-common.jar")
compileClasspath += files("${jboss_common_lib}/scheduler-plugin.jar")
compileClasspath += files("${jboss_common_lib}/servlet-api.jar")
compileClasspath += files("${myotherpackage_lib_thirdparty}/jboss-5.1.0.GA/hibernate-core-4.2.1.final.jar")
compileClasspath += files("${myotherpackage_lib_thirdparty}/jboss-5.1.0.GA/ejb3-persistence.jar")
compileClasspath += files("${myotherpackage_lib_thirdparty}/jboss-5.1.0.GA/jboss-javaee.jar")
compileClasspath += files("${myotherpackage_lib_thirdparty}/jboss-5.1.0.GA/jboss-j2se.jar")
compileClasspath += files("${myotherpackage_lib_thirdparty}/jboss-5.1.0.GA/jsp-api.jar")
compileClasspath += fileTree(dir: "${jboss_common_lib}", include: ['*.jar'])
compileClasspath += fileTree(dir: "${jboss_server_mypackage2ear}", include: ['*.jar'])
compileClasspath += fileTree(dir: "${mypackage_code_src_www}/WEB-INF/lib", include: ['*.*'])
}
}
}

在 ant 编译中,它工作得很好,但在 gradle 上它无法识别在 sourceSet 上声明的任何依赖项。 还尝试在我的依赖项{}标签上添加依赖项,但它仍然不起作用。 到处搜索,找不到解决方案

提前感谢!

我最终这样做了:

task doCompile(type: JavaCompile) {
classpath = sources //a file collection specifying a list of sources
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
destinationDir = file("$mypackage_build_output")
source = file("$mypackage_code_src_java")
}

还删除了源集,不再需要它了。 你可以用java插件来编译它,但我需要做的不仅仅是编译,所以坚持javacompile任务。

最新更新