简体   繁体   中英

Ant to Gradle, Problem with javaCompile task

I have the following ant task:

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

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. Also tried adding the dependency on my dependencies{} tag, but it still doesn't work. 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. You can acomplish this with the java plugin, but I needed to do more than compiling, so sticked with to the javacompile task.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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