简体   繁体   中英

how to exclude test dependences in gradle

first, I have a project like this:

project-a
   src
      main
          java
              A.java
      test
          java
              ATest.java

then, I have another project like this:

project-b
   src
      main
          java
              B.java
      test
          java
              BTest.java

the build.gradle configuration, project-b dependence project-a

dependencies{
    compile project(":project-a")
}

the question is BTest.java can access ATest.java, how to avoid this?

-------------------show more detail--------------- 在此处输入图片说明

settings.gradle

rootProject.name = 'test-dependence'

include 'project-a', 'project-b'

project-b/build.gradle

dependencies {
   compile project(":project-a")
   testCompile group: 'junit', name: 'junit', version: '4.12'
}

Unfortunately there's a bit of an impedence mismatch between Gradle modules and IntelliJ modules since Gradle allows multiple classpaths (configurations) in a module and IntelliJ has a single classpath per module.

Basically IntelliJ will allow BTest.java to access ATest.java but if you built from command line, Gradle won't allow it.

Try the following in intellij Gradle Settings.

Preferences -> Build, Execution, Deployment -> Build Tools -> Gradle: check create separate modules per source set

Related question here

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