protected static VersionDetails getVersionDetails(String versionString) {
   GradleVersion version = GradleVersion.version(versionString);
   if (version.compareTo(GradleVersion.version("1.11")) > 0) {
     return new R112VersionDetails(version.getVersion());
   }
   return new R18VersionDetails(version.getVersion());
 }
  @Test
  public void testDependencyScopeMerge() throws Exception {
    createSettingsFile("include 'api', 'impl' ");

    importProject(
        "allprojects {\n"
            + "  apply plugin: 'java'\n"
            + "\n"
            + "  sourceCompatibility = 1.5\n"
            + "  version = '1.0'\n"
            + "}\n"
            + "\n"
            + "dependencies {\n"
            + "  compile project(':api')\n"
            + "  testCompile project(':impl'), 'junit:junit:4.11'\n"
            + "  runtime project(':impl')\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("project_main", "api_main", DependencyScope.COMPILE);

    assertModuleModuleDepScope("project_main", "impl_main", DependencyScope.RUNTIME);
    assertModuleModuleDepScope("project_test", "impl_main", DependencyScope.COMPILE);

    assertModuleLibDepScope(
        "project_test", "Gradle: org.hamcrest:hamcrest-core:1.3", DependencyScope.COMPILE);
    assertModuleLibDepScope("project_test", "Gradle: junit:junit:4.11", DependencyScope.COMPILE);

    importProjectUsingSingeModulePerGradleProject();
    assertModules("project", "api", "impl");

    assertModuleModuleDepScope("project", "api", DependencyScope.COMPILE);

    if (GradleVersion.version(gradleVersion).compareTo(GradleVersion.version("1.12")) < 0) {
      assertModuleModuleDepScope("project", "impl", DependencyScope.RUNTIME);
    } else {
      assertModuleModuleDepScope("project", "impl", DependencyScope.RUNTIME, DependencyScope.TEST);
    }

    assertModuleLibDepScope(
        "project", "Gradle: org.hamcrest:hamcrest-core:1.3", DependencyScope.TEST);
    assertModuleLibDepScope("project", "Gradle: junit:junit:4.11", DependencyScope.TEST);
  }
  @Test
  @TargetVersions("2.0+")
  public void testTransitiveNonTransitiveDependencyScopeMerge() throws Exception {
    createSettingsFile("include 'project1'\n" + "include 'project2'\n");

    importProject(
        "project(':project1') {\n"
            + "  apply plugin: 'java'\n"
            + "  dependencies {\n"
            + "    compile 'junit:junit:4.11'\n"
            + "  }\n"
            + "}\n"
            + "\n"
            + "project(':project2') {\n"
            + "  apply plugin: 'java'\n"
            + "  dependencies.ext.strict = { projectPath ->\n"
            + "    dependencies.compile dependencies.project(path: projectPath, transitive: false)\n"
            + "    dependencies.runtime dependencies.project(path: projectPath, transitive: true)\n"
            + "    dependencies.testRuntime dependencies.project(path: projectPath, transitive: true)\n"
            + "  }\n"
            + "\n"
            + "  dependencies {\n"
            + "    strict ':project1'\n"
            + "  }\n"
            + "}\n");

    assertModules(
        "project",
        "project1",
        "project1_main",
        "project1_test",
        "project2",
        "project2_main",
        "project2_test");

    assertModuleModuleDeps("project2_main", "project1_main");
    assertModuleModuleDepScope("project2_main", "project1_main", DependencyScope.COMPILE);
    assertModuleLibDepScope(
        "project2_main", "Gradle: org.hamcrest:hamcrest-core:1.3", DependencyScope.RUNTIME);
    assertModuleLibDepScope("project2_main", "Gradle: junit:junit:4.11", DependencyScope.RUNTIME);

    if (GradleVersion.version(gradleVersion).compareTo(GradleVersion.version("2.5")) >= 0) {
      importProjectUsingSingeModulePerGradleProject();
      assertModules("project", "project1", "project2");
      assertModuleModuleDepScope("project2", "project1", DependencyScope.COMPILE);
      assertModuleLibDepScope(
          "project2", "Gradle: org.hamcrest:hamcrest-core:1.3", DependencyScope.RUNTIME);
      assertModuleLibDepScope("project2", "Gradle: junit:junit:4.11", DependencyScope.RUNTIME);
    }
  }
  @Test
  @TargetVersions("2.0+")
  public void testProvidedTransitiveDependencies() throws Exception {
    createSettingsFile("include 'projectA', 'projectB', 'projectC' ");
    importProject(
        "project(':projectA') {\n"
            + "  apply plugin: 'java'\n"
            + "}\n"
            + "project(':projectB') {\n"
            + "  apply plugin: 'java'\n"
            + "  dependencies {\n"
            + "    compile project(':projectA')\n"
            + "  }\n"
            + "}\n"
            + "project(':projectC') {\n"
            + "  apply plugin: 'war'\n"
            + "  dependencies {\n"
            + "    providedCompile project(':projectB')\n"
            + "  }\n"
            + "}");

    assertModules(
        "project",
        "projectA",
        "projectA_main",
        "projectA_test",
        "projectB",
        "projectB_main",
        "projectB_test",
        "projectC",
        "projectC_main",
        "projectC_test");

    assertModuleModuleDepScope("projectB_main", "projectA_main", DependencyScope.COMPILE);
    assertModuleModuleDepScope("projectC_main", "projectA_main", DependencyScope.PROVIDED);
    assertModuleModuleDepScope("projectC_main", "projectB_main", DependencyScope.PROVIDED);

    importProjectUsingSingeModulePerGradleProject();
    assertModules("project", "projectA", "projectB", "projectC");
    assertModuleModuleDepScope("projectB", "projectA", DependencyScope.COMPILE);
    if (GradleVersion.version(gradleVersion).compareTo(GradleVersion.version("2.5")) >= 0) {
      assertModuleModuleDepScope("projectC", "projectA", DependencyScope.PROVIDED);
    }
    assertModuleModuleDepScope("projectC", "projectB", DependencyScope.PROVIDED);
  }
示例#5
0
 private Distribution getDownloadedDistribution(String gradleVersion) {
   URI distUri;
   try {
     distUri =
         new URI(
             new DistributionLocator().getDistributionFor(GradleVersion.version(gradleVersion)));
   } catch (URISyntaxException e) {
     throw UncheckedException.asUncheckedException(e);
   }
   return getDistribution(distUri);
 }
  @Test
  public void testNonDefaultProjectConfigurationDependency() throws Exception {
    createSettingsFile("include 'project1'\n" + "include 'project2'\n");

    importProject(
        "project(':project1') {\n"
            + "  configurations {\n"
            + "    myConf {\n"
            + "      description = 'My Conf'\n"
            + "      transitive = true\n"
            + "    }\n"
            + "  }\n"
            + "  dependencies {\n"
            + "    myConf 'junit:junit:4.11'\n"
            + "  }\n"
            + "}\n"
            + "\n"
            + "project(':project2') {\n"
            + "  apply plugin: 'java'\n"
            + "  dependencies {\n"
            + "    compile project(path: ':project1', configuration: 'myConf')\n"
            + "  }\n"
            + "}\n");

    assertModules("project", "project1", "project2", "project2_main", "project2_test");

    assertModuleModuleDeps("project2_main");
    assertModuleLibDepScope(
        "project2_main", "Gradle: org.hamcrest:hamcrest-core:1.3", DependencyScope.COMPILE);
    assertModuleLibDepScope("project2_main", "Gradle: junit:junit:4.11", DependencyScope.COMPILE);

    importProjectUsingSingeModulePerGradleProject();
    assertModules("project", "project1", "project2");
    assertModuleModuleDeps("project2", "project1");
    if (GradleVersion.version(gradleVersion).compareTo(GradleVersion.version("2.0")) > 0) {
      assertModuleLibDepScope(
          "project2", "Gradle: org.hamcrest:hamcrest-core:1.3", DependencyScope.COMPILE);
      assertModuleLibDepScope("project2", "Gradle: junit:junit:4.11", DependencyScope.COMPILE);
    }
  }
  @Test
  public void testCompileAndRuntimeConfigurationsTransitiveDependencyMerge() throws Exception {
    createSettingsFile("include 'project1'\n" + "include 'project2'\n" + "include 'project-tests'");

    importProject(
        "subprojects {\n"
            + "  apply plugin: \"java\"\n"
            + "}\n"
            + "\n"
            + "project(\":project1\") {\n"
            + "  dependencies {\n"
            + "      compile 'org.apache.geronimo.specs:geronimo-jms_1.1_spec:1.0'\n"
            + "  }\n"
            + "}\n"
            + "\n"
            + "project(\":project2\") {\n"
            + "  dependencies {\n"
            + "      runtime 'org.apache.geronimo.specs:geronimo-jms_1.1_spec:1.1.1'\n"
            + "  }\n"
            + "}\n"
            + "\n"
            + "project(\":project-tests\") {\n"
            + "  dependencies {\n"
            + "      compile project(':project1')\n"
            + "      runtime project(':project2')\n"
            + "      compile 'junit:junit:4.11'\n"
            + "  }\n"
            + "}\n");

    assertModules(
        "project",
        "project1",
        "project1_main",
        "project1_test",
        "project2",
        "project2_main",
        "project2_test",
        "project-tests",
        "project-tests_main",
        "project-tests_test");

    assertModuleModuleDepScope("project-tests_main", "project1_main", DependencyScope.COMPILE);
    assertModuleModuleDepScope("project-tests_main", "project2_main", DependencyScope.RUNTIME);
    assertModuleLibDepScope(
        "project-tests_main",
        "Gradle: org.apache.geronimo.specs:geronimo-jms_1.1_spec:1.0",
        DependencyScope.COMPILE);
    assertModuleLibDepScope(
        "project-tests_main",
        "Gradle: org.apache.geronimo.specs:geronimo-jms_1.1_spec:1.1.1",
        DependencyScope.RUNTIME);

    importProjectUsingSingeModulePerGradleProject();

    assertModuleModuleDepScope("project-tests", "project1", DependencyScope.COMPILE);
    assertModuleModuleDepScope("project-tests", "project2", DependencyScope.RUNTIME);
    if (GradleVersion.version(gradleVersion).compareTo(GradleVersion.version("2.0")) > 0) {
      assertModuleLibDepScope(
          "project-tests",
          "Gradle: org.apache.geronimo.specs:geronimo-jms_1.1_spec:1.0",
          DependencyScope.COMPILE);
      assertModuleLibDepScope(
          "project-tests",
          "Gradle: org.apache.geronimo.specs:geronimo-jms_1.1_spec:1.1.1",
          DependencyScope.RUNTIME);
    }
  }
  @Test
  public void testDependencyWithDifferentClassifiers() throws Exception {
    final VirtualFile depJar = createProjectJarSubFile("lib/dep/dep/1.0/dep-1.0.jar");
    final VirtualFile depTestsJar = createProjectJarSubFile("lib/dep/dep/1.0/dep-1.0-tests.jar");
    final VirtualFile depNonJar = createProjectSubFile("lib/dep/dep/1.0/dep-1.0.someExt");

    importProject(
        "allprojects {\n"
            + "  apply plugin: 'java'\n"
            + "  sourceCompatibility = 1.5\n"
            + "  version = '1.0'\n"
            + "\n"
            + "  repositories {\n"
            + "    maven{ url file('lib') }\n"
            + "  }\n"
            + "}\n"
            + "\n"
            + "dependencies {\n"
            + "  compile 'dep:dep:1.0'\n"
            + "  testCompile 'dep:dep:1.0:tests'\n"
            + "  runtime 'dep:dep:1.0@someExt'\n"
            + "}");

    assertModules("project", "project_main", "project_test");

    assertModuleModuleDepScope("project_test", "project_main", DependencyScope.COMPILE);

    final String depName = "Gradle: dep:dep:1.0";
    assertModuleLibDep("project_main", depName, depJar.getUrl());
    assertModuleLibDepScope("project_main", depName, DependencyScope.COMPILE);
    assertModuleLibDep("project_test", depName, depJar.getUrl());
    assertModuleLibDepScope("project_test", depName, DependencyScope.COMPILE);

    final boolean isArtifactResolutionQuerySupported =
        GradleVersion.version(gradleVersion).compareTo(GradleVersion.version("2.0")) >= 0;
    final String depTestsName =
        isArtifactResolutionQuerySupported
            ? "Gradle: dep:dep:tests:1.0"
            : PathUtil.toPresentableUrl(depTestsJar.getUrl());
    assertModuleLibDep("project_test", depTestsName, depTestsJar.getUrl());
    assertModuleLibDepScope("project_test", depTestsName, DependencyScope.COMPILE);

    final String depNonJarName =
        isArtifactResolutionQuerySupported
            ? "Gradle: dep:dep:someExt:1.0"
            : PathUtil.toPresentableUrl(depNonJar.getUrl());
    assertModuleLibDep("project_main", depNonJarName, depNonJar.getUrl());
    assertModuleLibDepScope("project_main", depNonJarName, DependencyScope.RUNTIME);
    assertModuleLibDep("project_test", depNonJarName, depNonJar.getUrl());
    assertModuleLibDepScope("project_test", depNonJarName, DependencyScope.RUNTIME);

    importProjectUsingSingeModulePerGradleProject();
    assertModules("project");

    assertModuleLibDep("project", depName, depJar.getUrl());
    assertModuleLibDepScope("project", depName, DependencyScope.COMPILE);

    assertModuleLibDep("project", "Gradle: dep:dep:1.0:tests", depTestsJar.getUrl());
    assertModuleLibDepScope("project", "Gradle: dep:dep:1.0:tests", DependencyScope.TEST);

    assertModuleLibDep("project", "Gradle: dep:dep:1.0:someExt", depNonJar.getUrl());
    assertModuleLibDepScope("project", "Gradle: dep:dep:1.0:someExt", DependencyScope.RUNTIME);
  }
 private Distribution getDownloadedDistribution(String gradleVersion) {
   URI distUri =
       new DistributionLocator().getDistributionFor(GradleVersion.version(gradleVersion));
   return getDistribution(distUri);
 }