[GRADLE-1674] testCompile dependency is not included in the test scope of an idea project created by gradle Created: 15/Jul/11  Updated: 10/Feb/17  Resolved: 10/Feb/17

Status: Resolved
Project: Gradle
Affects Version/s: 1.0-milestone-3
Fix Version/s: None

Type: Bug
Reporter: Mike Mills Assignee: Unassigned
Resolution: Won't Fix Votes: 1


 Description   

Given this dependency declaration:

dependencies

{ runtime group: 'org.springframework.ws', name: 'spring-ws-core', version: '1.5.9' testCompile group: 'org.springframework', name: 'spring-context', version: '2.5.5' }

the spring-context jar is not included in the test scope in the Idea project.

There is a transitive dependency in spring-ws-core on spring-context 2.5.6. This dependency does appear in the runtime scope in the built Idea project.

This means that when you open the idea project and try to build, any test classes that use classes from spring-context (eg XmlClasspathContext) fail to compile when you try to build the project in Idea.

The workaround is to change the scope on that dependency.

Also note, that you get the same issue if you use version 2.5.6.SEC01 of spring-context (I think this is because Ivy resolves 2.5.5 < 2.5.6.SEC01 < 2.5.6 whereas maven resolves 2.5.5 < 2.5.6 < 2.5.6.SEC01)

If you use spring 3.x for the declared spring-context then you get the expected behavior, I think this is due to the declared dependency being considered newer.

Note that this declaration is fine when running "gradle test"



 Comments   
Comment by Russ Egan [ 21/Sep/11 ]

I think I just ran into this. It seems to be a weakness in idea. Idea doesn't let you specify dependencies twice, even if they are in different scopes. So you can't specify a single library to be both a runtime and a test scoped idea dependency.

It looks like there is a workaround though. If you define each idea dependency as a module library, you can create two differently scoped dependencies on the same jar. Each module library probably has to have a unique name, but can contain identical jars.

Going to see if it is possible to muck around in gradle's module generation code to do this...

Comment by Russ Egan [ 21/Sep/11 ]

Have a workaround. Though idea won't allow adding the library twice in idea's ui, it allows that in the .iml file.

So I modified the scope definitions used by the idea plugin. This ensures all testCompile and testRuntime dependencies are added to the idea module in the Test scope, even if they are also runtime (gradle) dependencies.

ideaModule {
    scopes.TEST.minus = [configurations.compile]
}

Seems like this should be the default.

Comment by Russ Egan [ 01/Dec/11 ]

Updated for M6:

project.plugins.withType(IdeaPlugin.class) {
  project.plugins.withType(JavaPlugin.class) {
    project.idea.module.scopes.TEST.minus = [project.configurations.compile]
  }
}
Comment by Benjamin Muschko [ 15/Nov/16 ]

As announced on the Gradle blog we are planning to completely migrate issues from JIRA to GitHub.

We intend to prioritize issues that are actionable and impactful while working more closely with the community. Many of our JIRA issues are inactionable or irrelevant. We would like to request your help to ensure we can appropriately prioritize JIRA issues you’ve contributed to.

Please confirm that you still advocate for your JIRA issue before December 10th, 2016 by:

  • Checking that your issues contain requisite context, impact, behaviors, and examples as described in our published guidelines.
  • Leave a comment on the JIRA issue or open a new GitHub issue confirming that the above is complete.

We look forward to collaborating with you more closely on GitHub. Thank you for your contribution to Gradle!

Comment by Benjamin Muschko [ 10/Feb/17 ]

Thanks again for reporting this issue. We haven't heard back from you after our inquiry from November 15th. We are closing this issue now. Please create an issue on GitHub if you still feel passionate about getting it resolved.

Generated at Wed Jun 30 12:01:33 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.