简体   繁体   English

Gradle SourceSet IntelliJ 与 Eclipse

[英]Gradle SourceSet IntelliJ vs. Eclipse

I'm indicating a problem, when i import a gradle project, which is originally built with Eclipse ,into IntelliJ .我表示一个问题,当我将最初使用Eclipse构建的 gradle 项目导入IntelliJ时。 In fact the project is a gradle-project , but when I import it into IntelliJ the IDE tells me that it deletes (some) duplicate content roots.事实上,该项目是一个gradle-project ,但是当我将它导入 IntelliJ 时,IDE 告诉我它删除了(一些)重复的内容根。

I get a balloon - telling me:我得到一个气球 - 告诉我:

Duplicate content roots deleted已删除重复的内容根

the message in the Event-Log is:事件日志中的消息是:

hh:mm[=22:58] Duplicate content roots detected hh:mm[=22:58] 检测到重复的内容根

Path [/Users/.../someProject/someModule] of module [someModuleName] was removed from modules [someModuleName.someSourceSetName]模块 [someModuleName] 的路径 [/Users/.../someProject/someModule] 已从模块 [someModuleName.someSourceSetName] 中删除

Also 1 more path was deduplicatetd.此外还有 1 个路径被重复数据删除。 See idea log for details有关详细信息,请参阅想法日志

In General it is a gradle-project , but I'm not able to run it in IntelliJ.一般来说,它是一个gradle-project ,但我无法在 IntelliJ 中运行它。 It builds using gradle-Wrapper on the command-line (./gradlew build) , but I would like to build with IntelliJ to improve the usage using (recompile+reload) and other features of the IDE .它在命令行 (./gradlew build)上使用gradle-Wrapper构建,但我想使用 IntelliJ 构建以改进使用 (recompile+reload) 和 IDE 的其他功能的使用

I have the following modules:我有以下模块:

  • A (A is the module i try to build) A (A是我尝试构建的模块)

  • B (B is the module, where i want to reuse the sourceSets 'main' AND 'testutils' of module A) B (B是模块,我想重用模块A的sourceSets'main'和'testutils')

Module A - consists of 3 sourceSets (=main, test, testutils):模块 A - 由 3 个源集(=main、test、testutils)组成:

src/main/java
src/test/java
src/testutils/java

Module A has the dependencies for testutils (consuming 'main'), test (consuming 'main' & 'testutils'), main (production java-src of the module)模块 A具有 testutils(使用“main”)、test(使用“main”和“testutils”)、main(模块的生产 java-src)的依赖项

And Module B where the sourceSet testutils of Module A is required within the main src and the tests ;模块 B ,其中模块A的 sourceSet testutilsmain src 和tests中是必需的; Module B - consumes sourceSet 'A/src/main/java' and 'A/src/testutils/java':模块 B - 使用 sourceSet 'A/src/main/java' 和 'A/src/testutils/java':

So my gradle files are (slightly shortened):所以我的 gradle 文件是(略微缩短):

A/build.gradle: A/build.gradle:

apply plugin: 'maven'

sourceSets {
    test.java.srcDirs +='src/testutils/java'
    testutils
}

dependencies {
    api project('someOtherProjectA')
    ...

    testImplementation project('someOtherProjectZZ')
    testutilsImplementation sourceSets.test.compileClasspath
}

task testutilsJar(type: Jar) {
    from sourceSets.testutils.output
      appendix 'testutils'
}

configurations {
    testutils
}

artifacts {
    testutils testutilsJar
}

uploadTestutils {
    repositories {
        mavenDeployer {
                configuration = configurations.testutils
                repository(url: mavenPublicRepository) {
                      authentication(userName: repoUsername, password: repoPassword)
                }
        }           
    }
}

publish.dependsOn uploadTestutils

B/build.gradlew: B/build.gradlew:

dependencies {
  api project('someOtherProjectB')

  api "someOtherDependency"
  ...

  testImplementation project('someOtherProjectC')       
  testImplementation project(path: ':A:theNameOfTheModule', configuration: 'testutils')
  ...
  
}

My DEV-System-Settings:我的开发系统设置:

JDK: 11.0.4
Gradle-Wrapper with Version: gradle-5.5.1
IntelliJ IDEA 2020.1 (Ultimate Edition) - Build #IU-201.6668.121, built on April 8, 2020
    Runtime version: 11.0.6+8-b765.25 x86_64
    VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
    macOS 10.15.4
    Memory: 3987M
    Cores: 16

I have already tried using the answers from我已经尝试过使用来自

I would be very grateful for an advise how I could manage my 'testutils'-SourceSet that it also builds the enclosing project with the embedded IntelliJ-Build:我将非常感谢我如何管理我的“testutils”-SourceSet 的建议,它还使用嵌入式 IntelliJ-Build 构建封闭项目:

  • Settings (= Build, Execution, Deployement > Build Tools > Gradle )设置(=构建、执行、部署>构建工具> Gradle
    • build and run using > 'IntelliJ IDEA' (instead of 'Gradle')使用 > 'IntelliJ IDEA' 构建和运行(而不是 'Gradle')
    • run tests using > 'IntelliJ IDEA' (instead of 'Gradle')使用 > 'IntelliJ IDEA' 运行测试(而不是 'Gradle')

I could find a solution for my problem.我可以为我的问题找到解决方案。

The sourceSet is defined in module A and referenced in module B. sourceSet 在模块 A 中定义并在模块 B 中引用。

The sourceSets of module A:模块 A 的源集:

  • main主要的
  • testutils (can use main and sees all dependencies of main AND test) testutils(可以使用 main 并查看 main AND test 的所有依赖项)
  • test (tests main + testutils)测试(测试主要 + testutils)

in module A (build.gradle):模块 A (build.gradle) 中:

apply plugin: 'maven'

sourceSets {
    testutils
    testutils.compileClasspath += sourceSets.main.output
    testutils.runtimeClasspath += sourceSets.main.output
    test.compileClasspath += sourceSets.testutils.output
    test.runtimeClasspath += sourceSets.testutils.output
}

dependencies {
    api project('someOtherProjectA')
    ...

    testImplementation project('someOtherProjectZZ')
    testutilsImplementation sourceSets.main.compileClasspath
}
...

in module B (build.gradle):模块 B (build.gradle) 中:

dependencies {
  testImplementation project(path: ':A:theNameOfTheModule', configuration: 'testutils')
  ...
}

Module B gets only access to the sourceSet testutils of Module A.模块 B 只能访问模块 A 的 sourceSet testutils

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

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