IDEA-155548 gradle: classpath does not include generated resources
[idea/community.git] / plugins / gradle / testSources / org / jetbrains / plugins / gradle / importing / GradleDependenciesImportingTest.java
1 /*
2  * Copyright 2000-2014 JetBrains s.r.o.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.jetbrains.plugins.gradle.importing;
17
18 import com.intellij.openapi.roots.DependencyScope;
19 import com.intellij.openapi.roots.LibraryOrderEntry;
20 import com.intellij.openapi.roots.OrderRootType;
21 import com.intellij.openapi.vfs.VirtualFile;
22 import com.intellij.util.PathUtil;
23 import org.gradle.util.GradleVersion;
24 import org.jetbrains.plugins.gradle.tooling.annotation.TargetVersions;
25 import org.junit.Test;
26
27 import java.util.List;
28
29 /**
30  * @author Vladislav.Soroka
31  * @since 6/30/2014
32  */
33 @SuppressWarnings("JUnit4AnnotatedMethodInJUnit3TestCase")
34 public class GradleDependenciesImportingTest extends GradleImportingTestCase {
35
36   @Test
37   public void testDependencyScopeMerge() throws Exception {
38     createSettingsFile("include 'api', 'impl' ");
39
40     importProject(
41       "allprojects {\n" +
42       "  apply plugin: 'java'\n" +
43       "\n" +
44       "  sourceCompatibility = 1.5\n" +
45       "  version = '1.0'\n" +
46       "}\n" +
47       "\n" +
48       "dependencies {\n" +
49       "  compile project(':api')\n" +
50       "  testCompile project(':impl'), 'junit:junit:4.11'\n" +
51       "  runtime project(':impl')\n" +
52       "}"
53     );
54
55     assertModules("project", "project_main", "project_test", "api", "api_main", "api_test", "impl", "impl_main", "impl_test");
56     assertModuleModuleDepScope("project_test", "project_main", DependencyScope.COMPILE);
57     assertModuleModuleDepScope("api_test", "api_main", DependencyScope.COMPILE);
58     assertModuleModuleDepScope("impl_test", "impl_main", DependencyScope.COMPILE);
59
60     assertModuleModuleDepScope("project_main", "api_main", DependencyScope.COMPILE);
61
62     assertModuleModuleDepScope("project_main", "impl_main", DependencyScope.RUNTIME);
63     assertModuleModuleDepScope("project_test", "impl_main", DependencyScope.COMPILE);
64
65     assertModuleLibDepScope("project_test", "Gradle: org.hamcrest:hamcrest-core:1.3", DependencyScope.COMPILE);
66     assertModuleLibDepScope("project_test", "Gradle: junit:junit:4.11", DependencyScope.COMPILE);
67
68
69     importProjectUsingSingeModulePerGradleProject();
70     assertModules("project", "api", "impl");
71
72     assertModuleModuleDepScope("project", "api", DependencyScope.COMPILE);
73
74     if(GradleVersion.version(gradleVersion).compareTo(GradleVersion.version("1.12")) < 0) {
75       assertModuleModuleDepScope("project", "impl", DependencyScope.RUNTIME);
76     } else {
77       assertModuleModuleDepScope("project", "impl", DependencyScope.RUNTIME, DependencyScope.TEST);
78     }
79
80     assertModuleLibDepScope("project", "Gradle: org.hamcrest:hamcrest-core:1.3", DependencyScope.TEST);
81     assertModuleLibDepScope("project", "Gradle: junit:junit:4.11", DependencyScope.TEST);
82   }
83
84   @Test
85   @TargetVersions("2.0+")
86   public void testTransitiveNonTransitiveDependencyScopeMerge() throws Exception {
87     createSettingsFile("include 'project1'\n" +
88                        "include 'project2'\n");
89
90     importProject(
91       "project(':project1') {\n" +
92       "  apply plugin: 'java'\n" +
93       "  dependencies {\n" +
94       "    compile 'junit:junit:4.11'\n" +
95       "  }\n" +
96       "}\n" +
97       "\n" +
98       "project(':project2') {\n" +
99       "  apply plugin: 'java'\n" +
100       "  dependencies.ext.strict = { projectPath ->\n" +
101       "    dependencies.compile dependencies.project(path: projectPath, transitive: false)\n" +
102       "    dependencies.runtime dependencies.project(path: projectPath, transitive: true)\n" +
103       "    dependencies.testRuntime dependencies.project(path: projectPath, transitive: true)\n" +
104       "  }\n" +
105       "\n" +
106       "  dependencies {\n" +
107       "    strict ':project1'\n" +
108       "  }\n" +
109       "}\n"
110     );
111
112     assertModules("project", "project1", "project1_main", "project1_test", "project2", "project2_main", "project2_test");
113
114     assertModuleModuleDeps("project2_main", "project1_main");
115     assertModuleModuleDepScope("project2_main", "project1_main", DependencyScope.COMPILE);
116     assertModuleLibDepScope("project2_main", "Gradle: org.hamcrest:hamcrest-core:1.3", DependencyScope.RUNTIME);
117     assertModuleLibDepScope("project2_main", "Gradle: junit:junit:4.11", DependencyScope.RUNTIME);
118
119     if(GradleVersion.version(gradleVersion).compareTo(GradleVersion.version("2.5")) >= 0) {
120       importProjectUsingSingeModulePerGradleProject();
121       assertModules("project", "project1", "project2");
122       assertModuleModuleDepScope("project2", "project1", DependencyScope.COMPILE);
123       assertModuleLibDepScope("project2", "Gradle: org.hamcrest:hamcrest-core:1.3", DependencyScope.RUNTIME);
124       assertModuleLibDepScope("project2", "Gradle: junit:junit:4.11", DependencyScope.RUNTIME);
125     }
126   }
127
128   @Test
129   @TargetVersions("2.0+")
130   public void testProvidedDependencyScopeMerge() throws Exception {
131     createSettingsFile("include 'web'\n" +
132                        "include 'user'");
133
134     importProject(
135       "subprojects {\n" +
136       "  apply plugin: 'java'\n" +
137       "  configurations {\n" +
138       "    provided\n" +
139       "  }\n" +
140       "}\n" +
141       "\n" +
142       "project(':web') {\n" +
143       "  dependencies {\n" +
144       "    provided 'junit:junit:4.11'\n" +
145       "  }\n" +
146       "}\n" +
147       "project(':user') {\n" +
148       "  apply plugin: 'war'\n" +
149       "  dependencies {\n" +
150       "    compile project(':web')\n" +
151       "    providedCompile project(path: ':web', configuration: 'provided')\n" +
152       "  }\n" +
153       "}"
154     );
155
156     assertModules("project", "web", "web_main", "web_test", "user", "user_main", "user_test");
157
158     assertModuleLibDeps("web");
159     assertModuleLibDeps("web_main");
160     assertModuleLibDeps("web_test");
161
162     assertModuleModuleDeps("user_main", "web_main");
163     assertModuleModuleDepScope("user_main", "web_main", DependencyScope.COMPILE);
164     assertModuleLibDepScope("user_main", "Gradle: org.hamcrest:hamcrest-core:1.3", DependencyScope.PROVIDED);
165     assertModuleLibDepScope("user_main", "Gradle: junit:junit:4.11", DependencyScope.PROVIDED);
166   }
167
168   @Test
169   public void testCustomSourceSetsDependencies() throws Exception {
170     createSettingsFile("include 'api', 'impl' ");
171
172     importProject(
173       "allprojects {\n" +
174       "  apply plugin: 'java'\n" +
175       "\n" +
176       "  sourceCompatibility = 1.5\n" +
177       "  version = '1.0'\n" +
178       "}\n" +
179       "\n" +
180       "project(\"impl\") {\n" +
181       "  sourceSets {\n" +
182       "    myCustomSourceSet\n" +
183       "    myAnotherSourceSet\n" +
184       "  }\n" +
185       "  \n" +
186       "  dependencies {\n" +
187       "    myCustomSourceSetCompile sourceSets.main.output\n" +
188       "    myCustomSourceSetCompile project(\":api\")\n" +
189       "    myCustomSourceSetRuntime 'junit:junit:4.11'\n" +
190       "  }\n" +
191       "}\n"
192     );
193
194     assertModules("project", "project_main", "project_test", "api", "api_main", "api_test", "impl", "impl_main", "impl_test",
195                   "impl_myCustomSourceSet", "impl_myAnotherSourceSet");
196
197     assertModuleModuleDepScope("project_test", "project_main", DependencyScope.COMPILE);
198     assertModuleModuleDepScope("api_test", "api_main", DependencyScope.COMPILE);
199     assertModuleModuleDepScope("impl_test", "impl_main", DependencyScope.COMPILE);
200
201     assertModuleModuleDepScope("impl_myCustomSourceSet", "impl_main", DependencyScope.COMPILE);
202     assertModuleModuleDepScope("impl_myCustomSourceSet", "api_main", DependencyScope.COMPILE);
203     assertModuleLibDepScope("impl_myCustomSourceSet", "Gradle: org.hamcrest:hamcrest-core:1.3", DependencyScope.RUNTIME);
204     assertModuleLibDepScope("impl_myCustomSourceSet", "Gradle: junit:junit:4.11", DependencyScope.RUNTIME);
205   }
206
207   @Test
208   public void testDependencyWithDifferentClassifiers() throws Exception {
209     final VirtualFile depJar = createProjectJarSubFile("lib/dep/dep/1.0/dep-1.0.jar");
210     final VirtualFile depTestsJar = createProjectJarSubFile("lib/dep/dep/1.0/dep-1.0-tests.jar");
211     final VirtualFile depNonJar = createProjectSubFile("lib/dep/dep/1.0/dep-1.0.someExt");
212
213     importProject(
214       "allprojects {\n" +
215       "  apply plugin: 'java'\n" +
216       "  sourceCompatibility = 1.5\n" +
217       "  version = '1.0'\n" +
218       "\n" +
219       "  repositories {\n" +
220       "    maven{ url file('lib') }\n" +
221       "  }\n" +
222       "}\n" +
223       "\n" +
224       "dependencies {\n" +
225       "  compile 'dep:dep:1.0'\n" +
226       "  testCompile 'dep:dep:1.0:tests'\n" +
227       "  runtime 'dep:dep:1.0@someExt'\n" +
228       "}"
229     );
230
231     assertModules("project", "project_main", "project_test");
232
233     assertModuleModuleDepScope("project_test", "project_main", DependencyScope.COMPILE);
234
235     final String depName = "Gradle: dep:dep:1.0";
236     assertModuleLibDep("project_main", depName, depJar.getUrl());
237     assertModuleLibDepScope("project_main", depName, DependencyScope.COMPILE);
238     assertModuleLibDep("project_test", depName, depJar.getUrl());
239     assertModuleLibDepScope("project_test", depName, DependencyScope.COMPILE);
240
241     final boolean isArtifactResolutionQuerySupported = GradleVersion.version(gradleVersion).compareTo(GradleVersion.version("2.0")) >= 0;
242     final String depTestsName = isArtifactResolutionQuerySupported ? "Gradle: dep:dep:tests:1.0" : PathUtil.toPresentableUrl(depTestsJar.getUrl());
243     assertModuleLibDep("project_test", depTestsName, depTestsJar.getUrl());
244     assertModuleLibDepScope("project_test", depTestsName, DependencyScope.COMPILE);
245
246     final String depNonJarName = isArtifactResolutionQuerySupported ? "Gradle: dep:dep:someExt:1.0" : PathUtil.toPresentableUrl(depNonJar.getUrl());
247     assertModuleLibDep("project_main", depNonJarName, depNonJar.getUrl());
248     assertModuleLibDepScope("project_main", depNonJarName, DependencyScope.RUNTIME);
249     assertModuleLibDep("project_test", depNonJarName, depNonJar.getUrl());
250     assertModuleLibDepScope("project_test", depNonJarName, DependencyScope.RUNTIME);
251
252     importProjectUsingSingeModulePerGradleProject();
253     assertModules("project");
254
255     assertModuleLibDep("project", depName, depJar.getUrl());
256     assertModuleLibDepScope("project", depName, DependencyScope.COMPILE);
257
258     assertModuleLibDep("project", "Gradle: dep:dep:1.0:tests", depTestsJar.getUrl());
259     assertModuleLibDepScope("project", "Gradle: dep:dep:1.0:tests", DependencyScope.TEST);
260
261     assertModuleLibDep("project", "Gradle: dep:dep:1.0:someExt", depNonJar.getUrl());
262     assertModuleLibDepScope("project", "Gradle: dep:dep:1.0:someExt", DependencyScope.RUNTIME);
263   }
264
265   @Test
266   public void testProjectWithUnresolvedDependency() throws Exception {
267     final VirtualFile depJar = createProjectJarSubFile("lib/dep/dep/1.0/dep-1.0.jar");
268     importProject(
269       "apply plugin: 'java'\n" +
270       "\n" +
271       "repositories {\n" +
272       "  maven { url file('lib') }\n" +
273       "}\n" +
274       "dependencies {\n" +
275       "  compile 'dep:dep:1.0'\n" +
276       "  compile 'some:unresolvable-lib:0.1'\n" +
277       "}\n"
278     );
279
280     assertModules("project", "project_main", "project_test");
281
282     final String depName = "Gradle: dep:dep:1.0";
283     assertModuleLibDep("project_main", depName, depJar.getUrl());
284     assertModuleLibDepScope("project_main", depName, DependencyScope.COMPILE);
285     assertModuleLibDepScope("project_main", "Gradle: some:unresolvable-lib:0.1", DependencyScope.COMPILE);
286
287     List<LibraryOrderEntry> unresolvableDep = getModuleLibDeps("project_main", "Gradle: some:unresolvable-lib:0.1");
288     assertEquals(1, unresolvableDep.size());
289     LibraryOrderEntry unresolvableEntry = unresolvableDep.iterator().next();
290     assertFalse(unresolvableEntry.isModuleLevel());
291     assertEquals(DependencyScope.COMPILE, unresolvableEntry.getScope());
292     String[] unresolvableEntryUrls = unresolvableEntry.getUrls(OrderRootType.CLASSES);
293     assertEquals(1, unresolvableEntryUrls.length);
294     assertTrue(unresolvableEntryUrls[0].contains("Could not find some:unresolvable-lib:0.1"));
295
296     assertModuleLibDep("project_test", depName, depJar.getUrl());
297     assertModuleLibDepScope("project_test", depName, DependencyScope.COMPILE);
298
299     importProjectUsingSingeModulePerGradleProject();
300     assertModules("project");
301
302     assertModuleLibDep("project", depName, depJar.getUrl());
303     assertModuleLibDepScope("project", depName, DependencyScope.COMPILE);
304     assertModuleLibDepScope("project", "Gradle: unresolvable-lib-0.1:1", DependencyScope.COMPILE);
305
306     unresolvableDep = getModuleLibDeps("project", "Gradle: unresolvable-lib-0.1:1");
307     assertEquals(1, unresolvableDep.size());
308     unresolvableEntry = unresolvableDep.iterator().next();
309     assertTrue(unresolvableEntry.isModuleLevel());
310     assertEquals(DependencyScope.COMPILE, unresolvableEntry.getScope());
311     unresolvableEntryUrls = unresolvableEntry.getUrls(OrderRootType.CLASSES);
312     assertEquals(0, unresolvableEntryUrls.length);
313   }
314
315   @Test
316   public void testSourceSetOutputDirsAsRuntimeDependencies() throws Exception {
317     importProject(
318       "apply plugin: 'java'\n" +
319       "sourceSets.main.output.dir file(\"$buildDir/generated-resources/main\")"
320     );
321
322     assertModules("project", "project_main", "project_test");
323     final String path = pathFromBasedir("build/generated-resources/main");
324     final String depName = PathUtil.toPresentableUrl(path);
325     assertModuleLibDep("project_main", depName, "file://" + path);
326     assertModuleLibDepScope("project_main", depName, DependencyScope.RUNTIME);
327   }
328
329   @Test
330   public void testSourceSetOutputDirsAsRuntimeDependenciesOfDependantModules() throws Exception {
331     createSettingsFile("include 'projectA', 'projectB', 'projectC' ");
332     importProject(
333       "project(':projectA') {\n" +
334       "  apply plugin: 'java'\n" +
335       "  sourceSets.main.output.dir file(\"$buildDir/generated-resources/main\")\n" +
336       "}\n" +
337       "project(':projectB') {\n" +
338       "  apply plugin: 'java'\n" +
339       "  dependencies {\n" +
340       "    compile project(':projectA')\n" +
341       "  }\n" +
342       "}\n" +
343       "project(':projectC') {\n" +
344       "  apply plugin: 'java'\n" +
345       "  dependencies {\n" +
346       "    runtime project(':projectB')\n" +
347       "  }\n" +
348       "}"
349     );
350
351     assertModules("project", "projectA", "projectA_main", "projectA_test", "projectB", "projectB_main", "projectB_test", "projectC", "projectC_main", "projectC_test");
352
353     assertModuleModuleDepScope("projectB_main", "projectA_main", DependencyScope.COMPILE);
354     assertModuleModuleDepScope("projectC_main", "projectA_main", DependencyScope.RUNTIME);
355     assertModuleModuleDepScope("projectC_main", "projectB_main", DependencyScope.RUNTIME);
356
357     final String path = pathFromBasedir("projectA/build/generated-resources/main");
358     final String classesPath = "file://" + path;
359     final String depName = PathUtil.toPresentableUrl(path);
360     assertModuleLibDep("projectA_main", depName, classesPath);
361     assertModuleLibDepScope("projectA_main", depName, DependencyScope.RUNTIME);
362     assertModuleLibDep("projectB_main", depName, classesPath);
363     assertModuleLibDepScope("projectB_main", depName, DependencyScope.COMPILE);
364     assertModuleLibDep("projectC_main", depName, classesPath);
365     assertModuleLibDepScope("projectC_main", depName, DependencyScope.RUNTIME);
366   }
367
368   @Test
369   public void testProjectArtifactDependencyInTestAndArchivesConfigurations() throws Exception {
370     createSettingsFile("include 'api', 'impl' ");
371
372     importProject(
373       "allprojects {\n" +
374       "  apply plugin: 'java'\n" +
375       "}\n" +
376       "\n" +
377       "project(\"api\") {\n" +
378       "  configurations {\n" +
379       "    tests\n" +
380       "  }\n" +
381       "  task testJar(type: Jar, dependsOn: testClasses, description: \"archive the testClasses\") {\n" +
382       "    baseName = \"${project.archivesBaseName}-tests\"\n" +
383       "    classifier = \"tests\"\n" +
384       "    from sourceSets.test.output\n" +
385       "  }\n" +
386       "  artifacts {\n" +
387       "    tests testJar\n" +
388       "    archives testJar\n" +
389       "  }\n" +
390       "}\n" +
391       "project(\"impl\") {\n" +
392       "  dependencies {\n" +
393       "    testCompile  project(path: ':api', configuration: 'tests')\n" +
394       "  }\n" +
395       "}\n"
396     );
397
398     assertModules("project", "project_main", "project_test", "api", "api_main", "api_test", "impl", "impl_main", "impl_test");
399
400     assertModuleModuleDepScope("project_test", "project_main", DependencyScope.COMPILE);
401     assertModuleModuleDepScope("api_test", "api_main", DependencyScope.COMPILE);
402     assertModuleModuleDepScope("impl_test", "impl_main", DependencyScope.COMPILE);
403     assertModuleModuleDepScope("impl_test", "api_test", DependencyScope.COMPILE);
404
405     importProjectUsingSingeModulePerGradleProject();
406     assertModules("project","api", "impl");
407
408     assertModuleModuleDepScope("impl", "api", DependencyScope.TEST);
409   }
410
411   @Test
412   public void testCompileAndRuntimeConfigurationsTransitiveDependencyMerge() throws Exception {
413     createSettingsFile("include 'project1'\n" +
414                        "include 'project2'\n" +
415                        "include 'project-tests'");
416
417     importProject(
418       "subprojects {\n" +
419       "  apply plugin: \"java\"\n" +
420       "}\n" +
421       "\n" +
422       "project(\":project1\") {\n" +
423       "  dependencies {\n" +
424       "      compile 'org.apache.geronimo.specs:geronimo-jms_1.1_spec:1.0'\n" +
425       "  }\n" +
426       "}\n" +
427       "\n" +
428       "project(\":project2\") {\n" +
429       "  dependencies {\n" +
430       "      runtime 'org.apache.geronimo.specs:geronimo-jms_1.1_spec:1.1.1'\n" +
431       "  }\n" +
432       "}\n" +
433       "\n" +
434       "project(\":project-tests\") {\n" +
435       "  dependencies {\n" +
436       "      compile project(':project1')\n" +
437       "      runtime project(':project2')\n" +
438       "      compile 'junit:junit:4.11'\n" +
439       "  }\n" +
440       "}\n"
441     );
442
443     assertModules("project", "project1", "project1_main", "project1_test", "project2", "project2_main", "project2_test", "project-tests", "project-tests_main", "project-tests_test");
444
445     assertModuleModuleDepScope("project-tests_main", "project1_main", DependencyScope.COMPILE);
446     assertModuleModuleDepScope("project-tests_main", "project2_main", DependencyScope.RUNTIME);
447     assertModuleLibDepScope("project-tests_main", "Gradle: org.apache.geronimo.specs:geronimo-jms_1.1_spec:1.0", DependencyScope.COMPILE);
448     assertModuleLibDepScope("project-tests_main", "Gradle: org.apache.geronimo.specs:geronimo-jms_1.1_spec:1.1.1", DependencyScope.RUNTIME);
449
450     importProjectUsingSingeModulePerGradleProject();
451
452     assertModuleModuleDepScope("project-tests", "project1", DependencyScope.COMPILE);
453     assertModuleModuleDepScope("project-tests", "project2", DependencyScope.RUNTIME);
454     if(GradleVersion.version(gradleVersion).compareTo(GradleVersion.version("2.0")) > 0) {
455       assertModuleLibDepScope("project-tests", "Gradle: org.apache.geronimo.specs:geronimo-jms_1.1_spec:1.0", DependencyScope.COMPILE);
456       assertModuleLibDepScope("project-tests", "Gradle: org.apache.geronimo.specs:geronimo-jms_1.1_spec:1.1.1", DependencyScope.RUNTIME);
457     }
458   }
459
460   @Test
461   public void testNonDefaultProjectConfigurationDependency() throws Exception {
462     createSettingsFile("include 'project1'\n" +
463                        "include 'project2'\n");
464
465     importProject(
466       "project(':project1') {\n" +
467       "  configurations {\n" +
468       "    myConf {\n" +
469       "      description = 'My Conf'\n" +
470       "      transitive = true\n" +
471       "    }\n" +
472       "  }\n" +
473       "  dependencies {\n" +
474       "    myConf 'junit:junit:4.11'\n" +
475       "  }\n" +
476       "}\n" +
477       "\n" +
478       "project(':project2') {\n" +
479       "  apply plugin: 'java'\n" +
480       "  dependencies {\n" +
481       "    compile project(path: ':project1', configuration: 'myConf')\n" +
482       "  }\n" +
483       "}\n"
484     );
485
486     assertModules("project", "project1", "project2", "project2_main", "project2_test");
487
488     assertModuleModuleDeps("project2_main");
489     assertModuleLibDepScope("project2_main", "Gradle: org.hamcrest:hamcrest-core:1.3", DependencyScope.COMPILE);
490     assertModuleLibDepScope("project2_main", "Gradle: junit:junit:4.11", DependencyScope.COMPILE);
491
492     importProjectUsingSingeModulePerGradleProject();
493     assertModules("project", "project1", "project2");
494     assertModuleModuleDeps("project2", "project1");
495     if(GradleVersion.version(gradleVersion).compareTo(GradleVersion.version("2.0")) > 0) {
496       assertModuleLibDepScope("project2", "Gradle: org.hamcrest:hamcrest-core:1.3", DependencyScope.COMPILE);
497       assertModuleLibDepScope("project2", "Gradle: junit:junit:4.11", DependencyScope.COMPILE);
498     }
499   }
500
501   @Test
502   @TargetVersions("2.0+")
503   public void testTestModuleDependencyAsArtifactFromTestSourceSetOutput() throws Exception {
504     createSettingsFile("include 'project1'\n" +
505                        "include 'project2'\n");
506
507     importProject(
508       "project(':project1') {\n" +
509       "  apply plugin: 'java'\n" +
510       "  configurations {\n" +
511       "    testArtifacts\n" +
512       "  }\n" +
513       "\n" +
514       "  task testJar(type: Jar) {\n" +
515       "    classifier = 'tests'\n" +
516       "    from sourceSets.test.output\n" +
517       "  }\n" +
518       "\n" +
519       "  artifacts {\n" +
520       "    testArtifacts testJar\n" +
521       "  }\n" +
522       "}\n" +
523       "\n" +
524       "project(':project2') {\n" +
525       "  apply plugin: 'java'\n" +
526       "  dependencies {\n" +
527       "    testCompile project(path: ':project1', configuration: 'testArtifacts')\n" +
528       "  }\n" +
529       "}\n"
530     );
531
532     assertModules("project", "project1", "project1_main", "project1_test", "project2", "project2_main", "project2_test");
533
534     assertModuleModuleDeps("project2_main");
535     assertModuleModuleDeps("project2_test", "project1_test", "project2_main");
536
537     importProjectUsingSingeModulePerGradleProject();
538     assertModules("project", "project1", "project2");
539     assertModuleModuleDeps("project2", "project1");
540   }
541
542   @Test
543   @TargetVersions("2.5+")
544   public void testProjectSubstitutions() throws Exception {
545     createSettingsFile("include 'core'\n" +
546                        "include 'service'\n" +
547                        "include 'util'\n");
548
549     importProject(
550       "subprojects {\n" +
551       "  apply plugin: 'java'\n" +
552       "  configurations.all {\n" +
553       "    resolutionStrategy.dependencySubstitution {\n" +
554       "      substitute module('mygroup:core') with project(':core')\n" +
555       "      substitute project(':util') with module('junit:junit:4.11')\n" +
556       "    }\n" +
557       "  }\n" +
558       "}\n" +
559       "\n" +
560       "repositories { mavenCentral() }\n" +
561       "\n" +
562       "project(':core') {\n" +
563       "  apply plugin: 'java'\n" +
564       "  repositories { mavenCentral() }\n" +
565       "  dependencies {\n" +
566       "    compile project(':util')\n" +
567       "  }\n" +
568       "}\n" +
569       "\n" +
570       "project(':service') {\n" +
571       "  dependencies {\n" +
572       "    compile 'mygroup:core:latest.release'\n" +
573       "  }\n" +
574       "}\n"
575     );
576
577     assertModules("project", "core", "core_main", "core_test", "service", "service_main", "service_test", "util", "util_main", "util_test");
578
579     assertModuleModuleDeps("service_main", "core_main");
580     assertModuleModuleDepScope("service_main", "core_main", DependencyScope.COMPILE);
581     assertModuleLibDepScope("service_main", "Gradle: org.hamcrest:hamcrest-core:1.3", DependencyScope.COMPILE);
582     assertModuleLibDepScope("service_main", "Gradle: junit:junit:4.11", DependencyScope.COMPILE);
583
584     importProjectUsingSingeModulePerGradleProject();
585     assertModules("project", "core", "service", "util");
586
587     assertModuleModuleDeps("service", "core");
588     assertModuleModuleDepScope("service", "core", DependencyScope.COMPILE);
589     assertModuleLibDepScope("service", "Gradle: org.hamcrest:hamcrest-core:1.3", DependencyScope.COMPILE);
590     assertModuleLibDepScope("service", "Gradle: junit:junit:4.11", DependencyScope.COMPILE);
591   }
592
593   @Test
594   @TargetVersions("2.12+")
595   public void testCompileOnlyScope() throws Exception {
596     importProject(
597       "apply plugin: 'java'\n" +
598       "dependencies {\n" +
599       "  compileOnly 'junit:junit:4.11'\n" +
600       "}"
601     );
602
603     assertModules("project", "project_main", "project_test");
604     assertModuleModuleDepScope("project_test", "project_main", DependencyScope.COMPILE);
605
606     assertModuleLibDepScope("project_main", "Gradle: org.hamcrest:hamcrest-core:1.3", DependencyScope.PROVIDED);
607     assertModuleLibDepScope("project_main", "Gradle: junit:junit:4.11", DependencyScope.PROVIDED);
608
609     assertModuleLibDeps("project_test");
610
611     importProjectUsingSingeModulePerGradleProject();
612     assertModules("project");
613
614     assertModuleLibDepScope("project", "Gradle: org.hamcrest:hamcrest-core:1.3", DependencyScope.PROVIDED);
615     assertModuleLibDepScope("project", "Gradle: junit:junit:4.11", DependencyScope.PROVIDED);
616   }
617
618   @Test
619   @TargetVersions("2.12+")
620   public void testNonTransitiveConfiguration() throws Exception {
621     importProject(
622       "apply plugin: 'java'\n" +
623       "configurations {\n" +
624       "  compile.transitive = false\n" +
625       "}\n" +
626       "\n" +
627       "dependencies {\n" +
628       "  compile 'junit:junit:4.11'\n" +
629       "}"
630     );
631
632     assertModules("project", "project_main", "project_test");
633     assertModuleModuleDepScope("project_test", "project_main", DependencyScope.COMPILE);
634
635     assertModuleLibDepScope("project_main", "Gradle: junit:junit:4.11", DependencyScope.COMPILE);
636     assertModuleLibDepScope("project_main", "Gradle: org.hamcrest:hamcrest-core:1.3", DependencyScope.PROVIDED);
637
638     assertModuleLibDepScope("project_test", "Gradle: junit:junit:4.11", DependencyScope.COMPILE);
639     assertModuleLibDepScope("project_test", "Gradle: org.hamcrest:hamcrest-core:1.3", DependencyScope.COMPILE);
640
641     importProjectUsingSingeModulePerGradleProject();
642     assertModules("project");
643
644     assertModuleLibDepScope("project", "Gradle: junit:junit:4.11", DependencyScope.COMPILE);
645     assertModuleLibDepScope("project", "Gradle: org.hamcrest:hamcrest-core:1.3", DependencyScope.PROVIDED, DependencyScope.RUNTIME);
646   }
647 }