简体   繁体   English

Ant 到 Gradle,javaCompile 任务问题

[英]Ant to Gradle, Problem with javaCompile task

I have the following ant task:我有以下 ant 任务:

<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>

I'm trying to convert it to a gradle, so far I have the following task:我正在尝试将其转换为 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")
}

Also have my sourceset defined as follows:还将我的源集定义如下:

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: ['*.*'])
        }
    }
}

In the ant compilation it works great, but on gradle it doesnt recognize any of the dependencies declared on the sourceSet.在 ant 编译中它工作得很好,但在 gradle 上它不识别在 sourceSet 上声明的任何依赖项。 Also tried adding the dependency on my dependencies{} tag, but it still doesn't work.还尝试在我的 dependencies{} 标签上添加依赖项,但它仍然不起作用。 Searched everywhere and can't find a solution到处搜索,找不到解决方案

Thanks in advance!提前致谢!

I ended up doing this:我最终这样做了:

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")
}

also deleted the sourceSet, didn't need it anymore.还删除了sourceSet,不再需要它了。 You can acomplish this with the java plugin, but I needed to do more than compiling, so sticked with to the javacompile task.您可以使用 java 插件来完成此操作,但我需要做的不仅仅是编译,所以坚持使用 javacompile 任务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM