简体   繁体   中英

Do not install gradle sub-project as external dependency

I have the following gradle multi-project structure.

root-project
   -A
     build.gradle
   -B
     build.gradle
 build.gradle
 settings.gradle

A has some plain java code and a couple of external dependencies. B has included A as compile(':A') . B also has a maven plugin applied as apply plugin: 'maven' .

Now my problem is whenever I do ./gradlew install , B includes A as an external maven dependency. Whoever uses B is not able to compile because it does not find A . How can I skip applying maven plugin to A and include all of its code inside B ?

Either:

  1. Publish the artifact to an external or internal repository
  2. Depend on the project library directly as shown below.

-

// Project B
dependencies {
    implementation(project(":a"))
}

Ref:

We've many alternatives if project B is producing a jar, but in my case, it's supposed to be a maven dependency used by third parties. I could not find a straight solution for it. So I ended up adding adding A 's sources into B. Something like this in B's build.gradle:

 sourceSets {
    main {
        java {
            srcDir 'src/main/java'
            srcDir '../A/src/main/java'
        }
    }
}

Only disadvantage with this is that I've to include A 's dependencies in B as well. I would be happy to accept if someone has a more elegant approach.

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