IDEA-173957 IDEA 2017.2 EAP detects 'compile' dependency in a Gradle project as 'provided'

This commit is contained in:
Vladislav.Soroka
2017-06-06 12:10:01 +03:00
parent aea101abf1
commit 8d59ee0870
2 changed files with 44 additions and 8 deletions
@@ -978,6 +978,39 @@ public class GradleDependenciesImportingTest extends GradleImportingTestCase {
}
}
@Test
@TargetVersions("2.12+")
public void testCompileOnlyAndCompileScope() throws Exception {
createSettingsFile("include 'app'\n");
importProject(
"apply plugin: 'java'\n" +
"dependencies {\n" +
" compileOnly project(':app')\n" +
" compile 'junit:junit:4.11'\n" +
"}\n" +
"project(':app') {\n" +
" apply plugin: 'java'\n" +
" repositories {\n" +
" mavenCentral()\n" +
" }\n" +
" dependencies {\n" +
" compile 'junit:junit:4.11'\n" +
" }\n" +
"}"
);
assertModules("project", "project_main", "project_test", "app", "app_main", "app_test");
assertModuleModuleDepScope("project_main", "app_main", DependencyScope.PROVIDED);
assertModuleLibDepScope("project_main", "Gradle: org.hamcrest:hamcrest-core:1.3", DependencyScope.COMPILE);
assertModuleLibDepScope("project_main", "Gradle: junit:junit:4.11", DependencyScope.COMPILE);
assertModuleModuleDeps("project_test", "project_main");
assertModuleModuleDepScope("project_test", "project_main", DependencyScope.COMPILE);
assertModuleLibDepScope("project_test", "Gradle: junit:junit:4.11", DependencyScope.COMPILE);
assertModuleLibDepScope("project_test", "Gradle: org.hamcrest:hamcrest-core:1.3", DependencyScope.COMPILE);
}
@Test
@TargetVersions("3.4+")
public void testJavaLibraryPluginConfigurations() throws Exception {
@@ -32,7 +32,6 @@ import org.gradle.api.artifacts.component.ModuleComponentIdentifier
import org.gradle.api.artifacts.component.ModuleComponentSelector
import org.gradle.api.artifacts.component.ProjectComponentIdentifier
import org.gradle.api.artifacts.component.ProjectComponentSelector
import org.gradle.api.artifacts.dsl.DependencyHandler
import org.gradle.api.artifacts.result.*
import org.gradle.api.plugins.WarPlugin
import org.gradle.api.specs.Specs
@@ -44,6 +43,7 @@ import org.gradle.api.tasks.compile.AbstractCompile
import org.gradle.language.base.artifact.SourcesArtifact
import org.gradle.language.java.artifact.JavadocArtifact
import org.gradle.plugins.ide.idea.IdeaPlugin
import org.gradle.util.GUtil
import org.gradle.util.GradleVersion
import org.jetbrains.annotations.NotNull
import org.jetbrains.annotations.Nullable
@@ -210,6 +210,9 @@ class DependencyResolverImpl implements DependencyResolver {
Collection<ExternalDependency> result = new ArrayList<>()
// resolve compile dependencies
def isMainSourceSet = sourceSet.name == SourceSet.MAIN_SOURCE_SET_NAME
String deprecatedCompileConfigurationName = isMainSourceSet ? "compile" : GUtil.toCamelCase(sourceSet.name) + "Compile"
def deprecatedCompileConfiguration = myProject.configurations.findByName(deprecatedCompileConfigurationName)
def compileConfigurationName = sourceSet.compileConfigurationName
def compileClasspathConfiguration = myProject.configurations.findByName(compileConfigurationName + 'Classpath')
def originCompileConfiguration = myProject.configurations.findByName(compileConfigurationName)
@@ -238,17 +241,17 @@ class DependencyResolverImpl implements DependencyResolver {
// since version 3.4 compileOnly no longer extends compile
// so, we can use compileOnly configuration for the check
Object[] resolvedObjArray = resolvedObj instanceof Collection ? ((Collection)resolvedObj).toArray() : [resolvedObj]
if (isJavaLibraryPluginSupported) {
if (compileOnlyConfiguration != null &&
(resolvedObj instanceof Collection ? compileOnlyConfiguration.containsAll(((Collection)resolvedObj).toArray()) :
compileOnlyConfiguration.contains(resolvedObj))) {
((AbstractExternalDependency)it).scope = providedScope
if (compileOnlyConfiguration != null && compileOnlyConfiguration.containsAll(resolvedObjArray)) {
// deprecated 'compile' configuration still can be used
if (deprecatedCompileConfiguration == null || !deprecatedCompileConfiguration.containsAll(resolvedObjArray)) {
((AbstractExternalDependency)it).scope = providedScope
}
}
}
else {
if (checkCompileOnlyDeps &&
(resolvedObj instanceof Collection ? !originCompileConfiguration.containsAll(((Collection)resolvedObj).toArray()) :
!originCompileConfiguration.contains(resolvedObj))) {
if (checkCompileOnlyDeps && !originCompileConfiguration.containsAll(resolvedObjArray)) {
((AbstractExternalDependency)it).scope = providedScope
}
}