简体   繁体   中英

Gradle jar including classes from dependency

I have a project having multiple modules say utils and core.
settings.gradle

include 'utils', 'core'

core/build.gradle

jar {
    destinationDir = file(LIB_DIR)
    manifest {
        attributes(
                'Main-Class': 'com.cohesity.spotlight.Main'
        )
    }
}

dependencies {
    compile files("$buildDir/libs/utils.jar")
}

The core.jar is containing classes from utils.jar. Why is this happening?

I think I know this one! (I've been baffled by it myself)

I'm guessing there are java source files packed inside utils.jar . By default javac will also compile these "implicit" sources alongside your sources from src/main/java . To stop this you'll want to pass -implicit:none to the compiler.

Eg:

tasks.withType(JavaCompile) {
   options.compilerArgs << '-implicit:none' 
} 

See https://docs.oracle.com/javase/7/docs/technotes/tools/solaris/javac.html (search for "implicit")

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