2

I'm indicating a problem, when i import a gradle project, which is originally built with Eclipse ,into 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.

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

Path [/Users/.../someProject/someModule] of module [someModuleName] was removed from modules [someModuleName.someSourceSetName]

Also 1 more path was deduplicatetd. See idea log for details

In General it is a gradle-project, but I'm not able to run it in 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.

I have the following modules:

  • A (A is the module i try to build)

  • B (B is the module, where i want to reuse the sourceSets 'main' AND 'testutils' of module A)

Module A - consists of 3 sourceSets (=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)

And Module B where the sourceSet testutils of Module A is required within the main src and the tests; Module B - consumes sourceSet 'A/src/main/java' and 'A/src/testutils/java':

So my gradle files are (slightly shortened):

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:

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:

  • Settings (=Build, Execution, Deployement > Build Tools > Gradle)
    • build and run using > 'IntelliJ IDEA' (instead of 'Gradle')
    • run tests using > 'IntelliJ IDEA' (instead of 'Gradle')
Community
  • 1
  • 1
duffy356
  • 3,678
  • 3
  • 32
  • 47
  • What error do you get in IDE? Do you use `idea` Gradle plugin? Can you provide [sample project](https://stackoverflow.com/help/minimal-reproducible-example)? – Andrey Apr 16 '20 at 09:01

1 Answers1

0

I could find a solution for my problem.

The sourceSet is defined in module A and referenced in module B.

The sourceSets of module A:

  • main
  • testutils (can use main and sees all dependencies of main AND test)
  • test (tests main + testutils)

in module 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):

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

Module B gets only access to the sourceSet testutils of Module A.

duffy356
  • 3,678
  • 3
  • 32
  • 47