Created
May 31, 2024 15:59
-
-
Save lptr/cbbd3d3a64b77925065f8202f797ac43 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/subprojects/public-api/build.gradle.kts b/subprojects/public-api/build.gradle.kts | |
index 6843632f414..9aba37fbbf6 100644 | |
--- a/subprojects/public-api/build.gradle.kts | |
+++ b/subprojects/public-api/build.gradle.kts | |
@@ -28,6 +28,7 @@ dependencies { | |
externalApi(libs.groovy) | |
} | |
+val testRepoLocation = layout.buildDirectory.dir("repos/test") | |
publishing { | |
publications { | |
create<MavenPublication>("maven") { | |
@@ -46,6 +47,29 @@ publishing { | |
} | |
} | |
} | |
+ repositories { | |
+ maven { | |
+ name = "test" | |
+ url = testRepoLocation.get().asFile.toURI() | |
+ } | |
+ } | |
+} | |
+ | |
+val testRepoElements = configurations.consumable("testRepoElements") { | |
+ outgoing.artifact(testRepoLocation) { | |
+ builtBy( "publishMavenPublicationToTestRepository") | |
+ } | |
+ // TODO: De-duplicate this. See publish-public-libraries | |
+ attributes { | |
+ attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage.JAVA_RUNTIME)) | |
+ attribute(Category.CATEGORY_ATTRIBUTE, project.objects.named(Category.LIBRARY)) | |
+ attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, project.objects.named("gradle-local-repository")) | |
+ attribute(Bundling.BUNDLING_ATTRIBUTE, project.objects.named(Bundling.EMBEDDED)) | |
+ } | |
+} | |
+ | |
+(components["gradleApi"] as AdhocComponentWithVariants).addVariantsFromConfiguration(testRepoElements.get()) { | |
+ mapToOptional() // The POM should not include dependencies of this configuration | |
} | |
// TODO De-duplicate this | |
diff --git a/testing/public-api-tests/build.gradle.kts b/testing/public-api-tests/build.gradle.kts | |
index ea3c311df4d..3ebd8f2bc17 100644 | |
--- a/testing/public-api-tests/build.gradle.kts | |
+++ b/testing/public-api-tests/build.gradle.kts | |
@@ -1,3 +1,5 @@ | |
+import gradlebuild.integrationtests.tasks.IntegrationTest | |
+ | |
/* | |
* Copyright 2024 the original author or authors. | |
* | |
@@ -22,6 +24,28 @@ plugins { | |
// id("gradlebuild.integration-tests") | |
} | |
+val testRepo = configurations.dependencyScope("testRepo") | |
+val resolveTestRepo = configurations.resolvable("resolveTestRepo") { | |
+ attributes { | |
+ attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage.JAVA_RUNTIME)) | |
+ attribute(Category.CATEGORY_ATTRIBUTE, project.objects.named(Category.LIBRARY)) | |
+ attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, project.objects.named("gradle-local-repository")) | |
+ attribute(Bundling.BUNDLING_ATTRIBUTE, project.objects.named(Bundling.EMBEDDED)) | |
+ } | |
+} | |
+ | |
dependencies { | |
+ testRepo(project(":public-api")) | |
integTestDistributionRuntimeOnly(project(":distributions-jvm")) | |
} | |
+ | |
+class ApiJarTestRepoLocationCommandLineArgumentProvider(val repoLocation: Provider<FileSystemLocation>) : CommandLineArgumentProvider { | |
+ override fun asArguments() = | |
+ listOf("-DintegTest.apiJarRepoLocation=${repoLocation.get().asFile.absolutePath}") | |
+} | |
+ | |
+tasks.withType<IntegrationTest>() { | |
+ jvmArgumentProviders.add(ApiJarTestRepoLocationCommandLineArgumentProvider( | |
+ resolveTestRepo.flatMap { it.elements }.map { it.first() } | |
+ )) | |
+} | |
diff --git a/testing/public-api-tests/src/integTest/groovy/org/gradle/api/PublicApiIntegrationTest.groovy b/testing/public-api-tests/src/integTest/groovy/org/gradle/api/PublicApiIntegrationTest.groovy | |
index 48b2f047d09..39f127d63f7 100644 | |
--- a/testing/public-api-tests/src/integTest/groovy/org/gradle/api/PublicApiIntegrationTest.groovy | |
+++ b/testing/public-api-tests/src/integTest/groovy/org/gradle/api/PublicApiIntegrationTest.groovy | |
@@ -20,10 +20,39 @@ import org.gradle.integtests.fixtures.AbstractIntegrationSpec | |
class PublicApiIntegrationTest extends AbstractIntegrationSpec { | |
void 'can use public API'() { | |
- def apiJarLocation = System.getProperty('integTest.apiJarLocation') | |
+ def apiJarRepoLocation = System.getProperty('integTest.apiJarRepoLocation') | |
+ println("Using API jar: $apiJarRepoLocation") | |
+ | |
+ buildKotlinFile << """ | |
+ plugins { | |
+ id("java-library") | |
+ } | |
+ | |
+ repositories { | |
+ maven { | |
+ url = uri("$apiJarRepoLocation") | |
+ } | |
+ } | |
+ | |
+ dependencies { | |
+ implementation("org.gradle.experimental:gradle-public-api:+") | |
+ } | |
+ """ | |
+ | |
+ file("src/main/java/org/example/PublishedApiTestPlugin.java") << """ | |
+ package org.example; | |
+ | |
+ import org.gradle.api.Plugin; | |
+ import org.gradle.api.Project; | |
+ | |
+ public class PublishedApiTestPlugin implements Plugin<Project> { | |
+ public void apply(Project project) { | |
+ project.getTasks().register("myTask", CustomTask.class); | |
+ } | |
+ } | |
+ """ | |
- println("Using API jar: $apiJarLocation") | |
expect: | |
- true | |
+ succeeds(":compileJava") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment