简体   繁体   English

如何排除gradle中的测试依赖

[英]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 build.gradle配置,project-b依赖project-a

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

the question is BTest.java can access ATest.java, how to avoid this?问题是 BTest.java 可以访问 ATest.java,如何避免这种情况?

-------------------show more detail--------------- -------------------显示更多细节--------------- 在此处输入图片说明

settings.gradle设置.gradle

rootProject.name = 'test-dependence'

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

project-b/build.gradle项目-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.不幸的是,Gradle 模块和 IntelliJ 模块之间存在一些阻抗不匹配,因为 Gradle 允许一个模块中有多个类路径(配置),而 IntelliJ 每个模块有一个类路径。

Basically IntelliJ will allow BTest.java to access ATest.java but if you built from command line, Gradle won't allow it.基本上 IntelliJ 将允许 BTest.java 访问 ATest.java 但如果您从命令行构建,Gradle 将不允许它。

Try the following in intellij Gradle Settings.在 Intellij Gradle 设置中尝试以下操作。

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

Related question here相关问题在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM