gradle: do not confuse main module artifacts with test artifacts
authorVladislav.Soroka <Vladislav.Soroka@jetbrains.com>
Fri, 25 Dec 2015 13:10:11 +0000 (16:10 +0300)
committerVladislav.Soroka <Vladislav.Soroka@jetbrains.com>
Fri, 25 Dec 2015 13:43:50 +0000 (16:43 +0300)
plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/BaseGradleProjectResolverExtension.java
plugins/gradle/testSources/org/jetbrains/plugins/gradle/importing/GradleDependenciesImportingTest.java

index d90bd43016433df7999d996f2b4a577c8c80bde1..76ef69eee0c97a39f563d60a079ddbac689dcf9c 100644 (file)
@@ -196,8 +196,12 @@ public class BaseGradleProjectResolverExtension implements GradleProjectResolver
           if (defaultArtifacts != null) {
             artifacts.addAll(defaultArtifacts);
           }
-          final Set<File> archivesArtifacts = externalProject.getArtifactsByConfiguration().get("archives");
-          if (archivesArtifacts != null) {
+          if (externalProject.getArtifactsByConfiguration().get("archives") != null) {
+            final Set<File> archivesArtifacts = ContainerUtil.newHashSet(externalProject.getArtifactsByConfiguration().get("archives"));
+            final Set<File> testsArtifacts = externalProject.getArtifactsByConfiguration().get("tests");
+            if (testsArtifacts != null) {
+              archivesArtifacts.removeAll(testsArtifacts);
+            }
             artifacts.addAll(archivesArtifacts);
           }
         } else if("test".equals(sourceSet.getName())) {
index 8adadf48661f6e255a2db6ab0004f6fc2223ac3d..9b3a3d28dbc0343e4a7cf5c406777365e17559f4 100644 (file)
@@ -206,4 +206,42 @@ public class GradleDependenciesImportingTest extends GradleImportingTestCase {
     assertModuleLibDep("project_main", depName, "file://" + path);
     assertModuleLibDepScope("project_main", depName, DependencyScope.RUNTIME);
   }
+
+  @Test
+  public void testProjectArtifactDependencyInTestAndArchivesConfigurations() throws Exception {
+    createSettingsFile("include 'api', 'impl' ");
+
+    importProject(
+      "allprojects {\n" +
+      "  apply plugin: 'java'\n" +
+      "}\n" +
+      "\n" +
+      "project(\"api\") {\n" +
+      "  configurations {\n" +
+      "    tests\n" +
+      "  }\n" +
+      "  task testJar(type: Jar, dependsOn: testClasses, description: \"archive the testClasses\") {\n" +
+      "    baseName = \"${project.archivesBaseName}-tests\"\n" +
+      "    classifier = \"tests\"\n" +
+      "    from sourceSets.test.output\n" +
+      "  }\n" +
+      "  artifacts {\n" +
+      "    tests testJar\n" +
+      "    archives testJar\n" +
+      "  }\n" +
+      "}\n" +
+      "project(\"impl\") {\n" +
+      "  dependencies {\n" +
+      "    testCompile  project(path: ':api', configuration: 'tests')\n" +
+      "  }\n" +
+      "}\n"
+    );
+
+    assertModules("project", "project_main", "project_test", "api", "api_main", "api_test", "impl", "impl_main", "impl_test");
+
+    assertModuleModuleDepScope("project_test", "project_main", DependencyScope.COMPILE);
+    assertModuleModuleDepScope("api_test", "api_main", DependencyScope.COMPILE);
+    assertModuleModuleDepScope("impl_test", "impl_main", DependencyScope.COMPILE);
+    assertModuleModuleDepScope("impl_test", "api_test", DependencyScope.COMPILE);
+  }
 }