Question on multiple java projects


(ray.tang) #1

Hi: how can I define a common external classpath for all sub-projects?


(René Groeschke) #2

In you root build.gradle file you can define dependencies for all subprojects by writing

subprojects {
   apply plugin: 'java'
      repositories {
       mavenCentral()
    }
      dependencies {
        testCompile 'junit:junit:4.8.2'
    }

Does this answer your questions? For further information have a look at the chapter 6.3 of the current user guide ( http://gradle.org/current/docs/userguide/userguide_single.html#sec:examples )

regards, René


(ray.tang) #3

Thanks for the reply. I read the chapter, but still confused on some of the dependencies. In my case, the root project looks like this.

root-build.gradle

subprojects {

apply plugin: ‘java’

apply plugin: ‘eclipse’

cxf.version = ‘2.3.5’

commons.version = ‘1.4.7’

version = ‘0-SNAPSHOT’

repositories {

mavenCentral artifactUrls: [“http://lnyce25218.bankofamerica.com:8081/nexus/content/groups/master”]

}

configurations {

cxf

commons

}

dependencies {

cxf ‘org.apache.cxf:cxf-rt-core:2.3.5’, ‘org.apache.cxf:cxf-rt-frontend-jaxws:2.3.5’, ‘org.apache.cxf:cxf-rt-frontend-simple:2.3.5’,‘org.apache.cxf:cxf-rt-transports-local:2.3.5’, ‘org.apache.cxf:cxf-rt-transports-http:2.3.5’, ‘org.apache.cxf:cxf-rt-transports-http-jetty:2.3.5’, ‘org.apache.cxf:cxf-rt-frontend-jaxrs:2.3.5’, ‘org.apache.cxf:cxf-rt-ws-security:2.3.5’, ‘org.apache.cxf:cxf-common-utilities:2.3.5’

commons ‘commons-digester:commons-digester:${commons.version}’, ‘commons-beanutils:commons-beanutils:1.8.3’, ‘commons-beanutils:commons-beanutils-core:1.8.3’, ‘commons-chain:commons-chain:${commons.version}’, ‘commons-validator:commons-validator:${commons.version}’, ‘commons-jxpath:commons-jxpath:1.3’, ‘commons-modeler:commons-modeler:2.0.1’, ‘commons-dbcp:commons-dbcp:1.4’, ‘commons-collections:commons-collections:3.2.1’, ‘commons-pool:commons-pool:1.5.5’, ‘commons-net:commons-net:2.2’, ‘commons-httpclient:commons-httpclient:3.1’, ‘commons-lang:commons-lang:2.5’, ‘commons-dbcp:commons-dbcp:${commons.version}’, ‘commons-logging:commons-logging:1.1.1’, ‘commons-discovery:commons-discovery:0.5’

}

jar {

manifest {

attributes ‘Implementation-Title’: ‘Gradle Quickstart’, ‘Implementation-Version’: version

}

} }

root-settings.gradle include “wrapper:cxf”

child-project: build.gradle buildscript {

repositories {

mavenCentral artifactUrls: [“http://lkcma00029.bankofamerica.com:8081/nexus/content/groups/master”]

}

dependencies {

compile project(’:main’)

} }

I kept on getting this error

  • Where: Build file ‘C:\projects\open\main\build.gradle’ line: 5

  • What went wrong: A problem occurred evaluating root project ‘main’. Cause: Could not find property ‘cxf’ on project ‘:wrapper’.

I am not sure what I did wrong here.

Thanks.


(René Groeschke) #4

The error message is caused by the naming of your cxf.version property. Gradle (precisely groovy) interprets this as a reference to an property named “version” of object cxf. The easiest workaround might be the renaming of the property to cxf_version. Same for commons.version

regards, René


(ray.tang) #5

Oh, I see. This makes sense.

Many Thanks.

Ray