Multi project depends on ANT project


(Brandon Lien) #1

I have a Java project which has 3rd party source code built via an ANT script. My goal is to avoid messing with any of that. My project is dependent on the jar files generated from the 3rd party project.

I’m looking to port my project into gradle which is currently also built via ant script, but I can’t seem to get the dependency and build order correct. The following works if I build 3rdParty via ./gradlew 3rdParty:build first, then build everything. I cant seem to force the ANT scrip to run, then check dependencies for available jars. Any suggestions welcome.

Directory Structure:

/3rdParty
       - build.xml
/src
    /main
        /java
            /src
                -Hello.java

build.gradle:

apply plugin 'java'
project(":3rdParty") {
      ant.importBuild 'build.xml'
}

dependencies {
    compile fileTree(dir: '3rdParty/', include: ['*.jar'])
}

jar {
    baseName = 'Gradle'
    version = '1'
}

apply plugin: 'application'
mainClassName = 'src.Hello'

 run {
       if (project.hasProperty("appArgs") ){
              args Eval.me(appArgs)
       }
 }

(Brandon Lien) #2

Not sure if it’s the ideal solution, but i found that adding the following line in dependencies to work.

dependencies {
    compileJava.dependsOn(':3rdParty:build')
    compile fileTree(dir: '3rdParty/', include: ['*.jar'])
}

(Schalk Cronjé) #3

You have pretty much figured out the correct approach, however, you should move compileJava.dependsOn outside of the dependencies block as semantically it will create mixed-metaphors. Rather have

dependencies {
    compile fileTree(dir: '3rdParty/', include: ['*.jar'])
}

compileJava {
  dependsOn ':3rdParty:build'
}

Have a look at https://github.com/ceylon/ceylon/blob/master/language/ant-language.gradle and https://github.com/ceylon/ceylon/blob/master/language/ant-language.gradle as an example of deeper Ant integration.


(Brandon Lien) #4

Thank you for the additional links.