diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/importing/GradleDependenciesImportingTest.java b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/importing/GradleDependenciesImportingTest.java index b4742abe08f4..f114e2f3a8da 100644 --- a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/importing/GradleDependenciesImportingTest.java +++ b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/importing/GradleDependenciesImportingTest.java @@ -19,6 +19,7 @@ import com.intellij.openapi.roots.libraries.LibraryTable; import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.Ref; +import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.ArrayUtil; @@ -38,6 +39,7 @@ import org.jetbrains.plugins.gradle.settings.GradleExecutionSettings; import org.jetbrains.plugins.gradle.settings.GradleSettings; import org.jetbrains.plugins.gradle.tooling.annotation.TargetVersions; import org.jetbrains.plugins.gradle.util.GradleConstants; +import org.junit.Assume; import org.junit.Test; import java.io.File; @@ -178,7 +180,10 @@ public class GradleDependenciesImportingTest extends GradleImportingTestCase { createSettingsFile("include 'api', 'impl' "); importProject(script(it -> { - it.allprojects(TestGradleBuildScriptBuilder::withJavaPlugin) + it.allprojects(p -> { + p.withJavaPlugin() + .withMavenCentral(); + }) .addImplementationDependency(it.project(":api")) .addTestImplementationDependency(it.project(":impl")) .addTestImplementationDependency("junit:junit:4.11") @@ -301,6 +306,7 @@ public class GradleDependenciesImportingTest extends GradleImportingTestCase { createBuildScriptBuilder() .subprojects(it -> { it + .withMavenCentral() .withJavaPlugin() .addPostfix("configurations { provided }"); }) @@ -336,7 +342,10 @@ public class GradleDependenciesImportingTest extends GradleImportingTestCase { createSettingsFile("include 'api', 'impl' "); importProject(script(it -> { - it.allprojects(TestGradleBuildScriptBuilder::withJavaPlugin) + it.allprojects( p -> { + p.withJavaPlugin() + .withMavenCentral(); + }) .project("impl", p -> { p.addPrefix("sourceSets {", " myCustomSourceSet", @@ -634,6 +643,7 @@ public class GradleDependenciesImportingTest extends GradleImportingTestCase { TestGradleBuildScriptBuilder builder = createBuildScriptBuilder(); importProject( builder.withJavaPlugin() + .withMavenCentral() .addPrefix("sourceSets.main.output.dir file(\"$buildDir/generated-resources/main\")") .addRuntimeOnlyDependency("junit:junit:4.11") .addRuntimeOnlyDependency(builder.code("files('lib/dep.jar')")) @@ -971,7 +981,11 @@ public class GradleDependenciesImportingTest extends GradleImportingTestCase { importProject( createBuildScriptBuilder() - .subprojects(TestGradleBuildScriptBuilder::withJavaPlugin) + .subprojects(it -> { + it + .withMavenCentral() + .withJavaPlugin(); + }) .project(":project1", it -> { it .withJavaLibraryPlugin() @@ -1038,26 +1052,25 @@ public class GradleDependenciesImportingTest extends GradleImportingTestCase { include 'project2' """); - String compileConfiguration = isJavaLibraryPluginSupported() ? "implementation" : "compile"; 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" + - " " + compileConfiguration + " project(path: ':project1', configuration: 'myConf')\n" + - " }\n" + - "}\n" + createBuildScriptBuilder() + .subprojects(it -> { it.withMavenCentral(); }) + .project(":project1", it -> { + it.addPrefix( """ + configurations { + myConf { + description = 'My Conf' + transitive = true + } + } + """) + .addDependency("myConf", "junit:junit:4.11"); + }) + .project(":project2", it -> { + it.withJavaPlugin() + .addImplementationDependency(it.project(":project1", "myConf")); + }) + .generate() ); assertModules("project", "project.project1", "project.project2", "project.project2.main", "project.project2.test"); @@ -1095,6 +1108,7 @@ public class GradleDependenciesImportingTest extends GradleImportingTestCase { createBuildScriptBuilder() .project(":project1", it -> { it + .withMavenCentral() .withJavaPlugin() .addPostfix("configurations { tests.extendsFrom testRuntime }") .withTask("testJar", "Jar", task -> { @@ -1115,6 +1129,7 @@ public class GradleDependenciesImportingTest extends GradleImportingTestCase { }) .project(":project2", it -> { it + .withMavenCentral() .withJavaPlugin() .addTestImplementationDependency(it.project(":project1", "tests")); }) @@ -1366,6 +1381,7 @@ public class GradleDependenciesImportingTest extends GradleImportingTestCase { importProject( createBuildScriptBuilder() .subprojects(p -> { + p.withMavenCentral(); p.withJavaPlugin(); if (isGradleOlderThan("8.0")) { p.addPrefix("configurations.all {", @@ -1424,6 +1440,7 @@ public class GradleDependenciesImportingTest extends GradleImportingTestCase { createBuildScriptBuilder() .subprojects(it -> { it + .withMavenCentral() .withJavaLibraryPlugin() .addVersion("1.0.0"); }) @@ -1489,11 +1506,11 @@ public class GradleDependenciesImportingTest extends GradleImportingTestCase { @TargetVersions("2.12+") public void testCompileOnlyScope() throws Exception { importProject( - """ - apply plugin: 'java' - dependencies { - compileOnly 'junit:junit:4.11' - }""" + createBuildScriptBuilder() + .withJavaPlugin() + .withMavenCentral() + .addDependency("compileOnly", "junit:junit:4.11") + .generate() ); assertModules("project", "project.main", "project.test"); @@ -1550,6 +1567,7 @@ public class GradleDependenciesImportingTest extends GradleImportingTestCase { TestGradleBuildScriptBuilder builder = createBuildScriptBuilder(); importProject( builder + .withMavenCentral() .withJavaPlugin() .addCompileOnlyDependency(builder.project(":app")) .addImplementationDependency("junit:junit:4.11") @@ -1584,6 +1602,7 @@ public class GradleDependenciesImportingTest extends GradleImportingTestCase { importProject( createBuildScriptBuilder() + .subprojects(it -> { it.withMavenCentral(); }) .project(":project1", p -> { p .withJavaPlugin() @@ -1713,6 +1732,7 @@ public class GradleDependenciesImportingTest extends GradleImportingTestCase { String testCompileConfiguration = isJavaLibraryPluginSupported() ? "testImplementation" : "testCompile"; importProject( createBuildScriptBuilder() + .subprojects(it -> { it.withMavenCentral(); }) .project(":project1", it -> { it.withJavaPlugin() .addPrefix("configurations {", @@ -1945,6 +1965,8 @@ public class GradleDependenciesImportingTest extends GradleImportingTestCase { @Test public void testSourcesExcludedFromGradleCacheOnDisabledFlag() throws Exception { + Assume.assumeFalse("Can not run on Windows. " + + "The test locks native library files in test directory and can not be torn down properly.", SystemInfo.isWindows); overrideGradleUserHome("project/cache"); var dependency = "junit:junit:4.12"; var dependencyName = "Gradle: junit:junit:4.12"; @@ -1963,6 +1985,8 @@ public class GradleDependenciesImportingTest extends GradleImportingTestCase { @Test public void testSourcesExcludedFromGradleCacheOnDisabledFlagWithIdeaPlugin() throws Exception { + Assume.assumeFalse("Can not run on Windows. " + + "The test locks native library files in test directory and can not be torn down properly.", SystemInfo.isWindows); overrideGradleUserHome("project/cache"); var dependency = "junit:junit:4.12"; var dependencyName = "Gradle: junit:junit:4.12"; @@ -1982,6 +2006,8 @@ public class GradleDependenciesImportingTest extends GradleImportingTestCase { @Test public void testSourcesExcludedFromGradleMultiModuleProjectCacheOnDisabledFlag() throws Exception { + Assume.assumeFalse("Can not run on Windows. " + + "The test locks native library files in test directory and can not be torn down properly.", SystemInfo.isWindows); overrideGradleUserHome("project/cache"); var dependency = "junit:junit:4.12"; var dependencyName = "Gradle: junit:junit:4.12"; @@ -2124,9 +2150,27 @@ public class GradleDependenciesImportingTest extends GradleImportingTestCase { todir: new File(gradle.gradleUserHomeDir, '/caches/ij_test_repo/test') } } - task removeALibFromGradleUserHome(type: Delete) { - delete new File(gradle.gradleUserHomeDir, '/caches/ij_test_repo/test') - followSymlinks = true}"""); + task removeALibFromGradleUserHome(type: DefaultTask) { + doLast { + def attemptsLeft = 10; + while (attemptsLeft > 0) { + attemptsLeft--; + try { + project.delete { + delete new File(gradle.gradleUserHomeDir, '/caches/ij_test_repo/test') + followSymlinks = true + } + break; + } catch (Exception e) { + if (attemptsLeft == 0) { + throw e; + } else { + Thread.sleep(1000); + } + } + } + } + }"""); importProject(createBuildScriptBuilder() .generate()); assertModules("project", @@ -2170,6 +2214,7 @@ public class GradleDependenciesImportingTest extends GradleImportingTestCase { importProject( createBuildScriptBuilder() .withJavaPlugin() + .withMavenCentral() .addImplementationDependency("junit:junit:4.11") .addPrefix("afterEvaluate {", " def mainSourceSet = sourceSets['main']", @@ -2196,6 +2241,7 @@ public class GradleDependenciesImportingTest extends GradleImportingTestCase { importProject( createBuildScriptBuilder() .withJavaPlugin() + .withMavenCentral() .addPostfix( " configurations {", " custom1", @@ -2209,7 +2255,7 @@ public class GradleDependenciesImportingTest extends GradleImportingTestCase { " custom2 'org.hamcrest:hamcrest-core:1.3'", " }", " compileJava { classpath += configurations.custom1 }", - " compileCustomSrcJava {classpath += configurations.custom2 }" + " compileCustomSrcJava { classpath += configurations.custom2 }" ) .generate() );