1

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--------------- enter image description here

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'
}
peacetrue
  • 186
  • 1
  • 15

1 Answers1

1

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

lance-java
  • 25,497
  • 4
  • 59
  • 101