Intellij dependencies not appearing with custom configuration


(Adrian Kelly) #1

Hi,

I’ve got a custom configuration for a functional test suite that I am applying to a war project as follows:

apply from: "$rootDir/gradle/apiFunctionalTest.gradle"

The task compiles and runs the code as expected with gradle but when I refresh the gradle view in Intelij, none of the external dependencies get pulled into the IDE and hence won’t compile in intellij. I’m wondering if there is something wrong with my configuration or if intellij cannot recognise external dependencies for custom configurations?

When I change the dependencies from ‘apiFunctionalTestCompile’ to ‘testCompile’ as follows injellij does pick up the dependencies but I suspect that this is applying the external dependencies to the projects main testCompile configuration?

dependencies {
  testCompile 'com.jayway.restassured:rest-assured:1.7.2'
  testCompile 'org.apache.pdfbox:pdfbox:1.2.1'
  testCompile 'org.seleniumhq.selenium:selenium-java:2.16.0'
  testCompile 'net.sourceforge.htmlunit:htmlunit:2.9'
  testCompile 'org.jsoup:jsoup:1.6.3'
  testCompile libs.jackson
}

Full configuration:

sourceSets {
  apiFunctionalTest {
    java.srcDir file('src/apiFunctional/java')
    resources.srcDir file('src/apiFunctional/resources')
      compileClasspath = sourceSets.main.output + sourceSets.test.output + configurations.apiFunctionalTestCompile
    runtimeClasspath = output + compileClasspath + configurations.apiFunctionalTestRuntime
  }
}
  configurations {
  apiFunctionalTestCompile.extendsFrom testCompile
  apiFunctionalTestRuntime.extendsFrom testRuntime
}
    dependencies {
  apiFunctionalTestCompile 'com.jayway.restassured:rest-assured:1.7.2'
  apiFunctionalTestCompile 'org.apache.pdfbox:pdfbox:1.2.1'
  apiFunctionalTestCompile 'org.seleniumhq.selenium:selenium-java:2.16.0'
  apiFunctionalTestCompile 'net.sourceforge.htmlunit:htmlunit:2.9'
  apiFunctionalTestCompile 'org.jsoup:jsoup:1.6.3'
  apiFunctionalTestCompile libs.jackson
}
  task apiFunctionalTest(type: Test) {
  description = 'Runs the api functional(java) tests.'
  group = 'verification'
    testClassesDir = sourceSets.apiFunctionalTest.output.classesDir
  classpath = sourceSets.apiFunctionalTest.runtimeClasspath
  reports.junitXml.destination = "$buildDir/reports/functional/xml"
  reports.html.destination = file("$buildDir/reports/functional/html")
}

(Radim Kubacki) #2

Each module in IDEA has basically two kinds of sources - production and test. There are a few classpath scopes controlling how sources and dependencies are used together when project is built and run. Gradle by default maps main and test sourceSets and related configurations to IDEA projects/modules.

Now if you want to add another sourceSet + configurations for your additional code you will need to customize the mapping between Gradle and IDEA.Take a look at the documentation - most interesting for you is http://www.gradle.org/docs/current/dsl/org.gradle.plugins.ide.idea.model.IdeaModule.html

You will want something like

idea {
  module {
    scopes.TEST.plus = configurations.apiFunctionalTestCompile
  }
}

(Adrian Kelly) #3

Thanks for the quick response! I’m currently not using the idea plugin, I was using it originally but it was troublesome. I came across the following http://forums.gradle.org/gradle/topics/the_idea_plugin_breaks_the_new_intellij_13_iml_configuration which recommends using idea’s built in gradle support rather than the plugin which seemed to work much better. Here is the layout for the particular sub project.

src – apiFunctional – integTest – main – test

integTest is again a custom configuration but it does not have external dependencies like ‘apiFunctional’ and all works fine in intellij. It sounds like the non-plugin gradle/idea support does not handle external dependencies for custom configurations?

integTest

sourceSets {
  integrationTest {
    java.srcDir file('src/integTest/java')
    resources.srcDir file('src/integTest/resources')
      compileClasspath += sourceSets.main.output + sourceSets.test.output
    runtimeClasspath += sourceSets.main.output + sourceSets.test.output
  }
}
  configurations {
  integrationTestCompile.extendsFrom testCompile
  integrationTestRuntime.extendsFrom testRuntime
}

(Radim Kubacki) #4

Build-it Gradle support in IDEA honors idea.module.scope customizations (at least to some degree). And this customization is what you need to tell IDEA how/where to add these dependencies.

Also if you have problems with idea plugin in Gradle it would be good to see what exactly is wrong there. Specific examples that can demonstrate these problem are best and can help us to improve it in the future.