1

I have been searching for an answer to my question, but I found none. I built an android project with many modules. The modules should be published in a repository (at first in the local maven repository). I've done a demo project with two simple projects pr1, pr2. Now I've added to pr2 the dependency for pr1.

compile ('de.test:project1:1.0.0')

After that, I can publish both artifacts.

Now, when I change the name from pr2 to aPr2, the dependency can not be resolved from in aPr2, because the jar file does not exist. The problem is that aPr2 is built before pr1.

How can I tell Gradle to build it in the correct order?

This is my Gradle file from one of the projects. Pr1 is similar, without dependency.

plugins {
    id 'java'
    id 'maven-publish'
    }
dependencies {
//    compile project(':project1')
    compile ('de.test:project1:1.0.0')
    testCompile 'junit:junit:4.12'
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
publishing {
    publications {
        publish(MavenPublication) {
            groupId 'de.test'
            artifactId 'project2'
            version '1.0.0'
            from components.java
        }
    }
}
Onema
  • 7,331
  • 12
  • 66
  • 102
Dagobert
  • 31
  • 5

1 Answers1

1

You need to modify your project configuration.

When you use components.java, the maven-publish plugin will set the groupId, artifactId and version from Gradle project configuration.

The default artifactId has been set with the name of the project (default: folder name). It is read-only, but you can override it. Create a settings.gradle file in subproject folder and set the module name:

rootProject.name = 'project1'

Write these lines into build.gradle file in root project dir for setup groupId and version for all project.

allprojects {
   group 'de.test'
   version '1.0.0'
}

If you setup everything correctly, you can remove comment from compile project(':project1')

You can build the project and you can publish your pom file with de.test:project:1.0.0 dependency.

bvarga
  • 716
  • 6
  • 12