How to switch between Project dependency and Snapshot dependency?

(Venkatesh Nannan) #1

We have a multiple modules in our Java project and each module publishes SNAPSHOT jar files to Nexus repository. All the sub-modules are directly dependent on the SNAPSHOT jar files.

During development, we want to depend on the Eclipse project rather than SNAPSHOT jars. So we introduced a flag which switches between the dependencies as shown below.

    compile project(':Core')
    compile project(':Module1')
    compile project(':Module2')
    compile 'com.test:core:0.1-SNAPSHOT'
    compile 'com.test:module1:0.1-SNAPSHOT'
    compile 'com.test:module2:0.1-SNAPSHOT'

Executing the following command generates the .classpath file as expected.

gradle eclipse -DsetupProject=true

Is there a better way to do this?

Can we use Gradle “Configurations” to achieve the same?

I could not find good examples for using Configurations.

(detelinyordanov) #2

I’m wondering how do you guarantee that every time the project is built, all modules depend on the just built artifacts instead of the SNAPSHOT ones available on your Nexus repository?

(Venkatesh Nannan) #3

I am not sure whether I understood your question correctly.

Gradle build running on our CI server (Jenkins) will depend only on the SNAPSHOT builds for the dependent projects as we don’t use any flags while building the projects.

We are using the “-DsetupProject=true” flag ONLY for the “gradle eclipse” task. This helps developers not to worry about snapshots.

(detelinyordanov) #4

I assume you are talking about a multiproject build, so ‘:Module1’ and ‘:Module2’ are subprojects. My question was - if let’s say Module1 depends on Module2 using an external module dependency rather than a project dependency:

//module1 build.gradle
dependencies {
    compile 'com.test:module2:0.1-SNAPSHOT'

Then isn’t it possible that if you build all modules (from the root project) using ‘gradle clean build’ - ‘:Module1’ could be built against the latest available ‘com.test:module2:0.1-SNAPSHOT’ on your Nexus repository (which could be some outdated version uploaded yesterday), rather than the ‘:Module2’ being built by this same build?