Merge "Pass repository URLs for ProjectSetupRule" into androidx-main
diff --git a/buildSrc/src/main/kotlin/androidx/build/SdkResourceGenerator.kt b/buildSrc/src/main/kotlin/androidx/build/SdkResourceGenerator.kt
index ee2e2ec..9ed6c50 100644
--- a/buildSrc/src/main/kotlin/androidx/build/SdkResourceGenerator.kt
+++ b/buildSrc/src/main/kotlin/androidx/build/SdkResourceGenerator.kt
@@ -20,6 +20,7 @@
import androidx.build.dependencies.KOTLIN_STDLIB
import org.gradle.api.DefaultTask
import org.gradle.api.Project
+import org.gradle.api.artifacts.repositories.MavenArtifactRepository
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.plugins.JavaPluginConvention
import org.gradle.api.tasks.Input
@@ -59,6 +60,9 @@
val kotlinStdlib: String = KOTLIN_STDLIB
@get:Input
+ lateinit var repositoryUrls: List<String>
+
+ @get:Input
val rootProjectPath: String = project.rootProject.rootDir.absolutePath
@get:Input
@@ -81,6 +85,8 @@
writer.write("kotlinStdlib=$kotlinStdlib\n")
writer.write("gradleVersion=$gradleVersion\n")
writer.write("rootProjectPath=$rootProjectPath\n")
+ val encodedRepositoryUrls = repositoryUrls.joinToString(",")
+ writer.write("repositoryUrls=$encodedRepositoryUrls\n")
writer.close()
}
@@ -97,6 +103,12 @@
it.localSupportRepo = project.getRepositoryDirectory().canonicalPath
it.gradleVersion = project.gradle.gradleVersion
it.outputFile.set(File(generatedDirectory, "sdk.prop"))
+ // Copy repositories used for the library project so that it can replicate the same
+ // maven structure in test.
+ it.repositoryUrls = project.repositories.filterIsInstance<MavenArtifactRepository>()
+ .map {
+ it.url.toString()
+ }
}
project.tasks.named("compileTestJava").configure { it.dependsOn(provider) }
diff --git a/room/integration-tests/incremental-annotation-processing/src/test/kotlin/androidx/room/gradle/RoomIncrementalAnnotationProcessingTest.kt b/room/integration-tests/incremental-annotation-processing/src/test/kotlin/androidx/room/gradle/RoomIncrementalAnnotationProcessingTest.kt
index 1bf80e6..109fc3e 100644
--- a/room/integration-tests/incremental-annotation-processing/src/test/kotlin/androidx/room/gradle/RoomIncrementalAnnotationProcessingTest.kt
+++ b/room/integration-tests/incremental-annotation-processing/src/test/kotlin/androidx/room/gradle/RoomIncrementalAnnotationProcessingTest.kt
@@ -91,8 +91,19 @@
@Before
fun setup() {
val projectRoot = projectSetup.rootDir
- val prebuiltsRoot = projectSetup.props.prebuiltsRoot
- val localSupportRepo = projectSetup.props.localSupportRepo
+ val repositoriesBlock = buildString {
+ appendLine("repositories {")
+ projectSetup.allRepositoryPaths.forEach {
+ appendLine(
+ """
+ maven {
+ url "$it"
+ }
+ """.trimIndent()
+ )
+ }
+ appendLine("}")
+ }
val agpDependency = projectSetup.props.agpDependency
// copy test project
@@ -102,10 +113,7 @@
File(projectRoot, "build.gradle").writeText(
"""
buildscript {
- repositories {
- maven { url "$prebuiltsRoot/androidx/external" }
- maven { url "$prebuiltsRoot/androidx/internal" }
- }
+ ${repositoriesBlock.prependIndent(" ")}
dependencies {
classpath "$agpDependency"
}
@@ -113,16 +121,7 @@
apply plugin: 'com.android.application'
- repositories {
- maven { url "$prebuiltsRoot/androidx/external" }
- maven { url "$localSupportRepo" }
- maven {
- url "$prebuiltsRoot/androidx/internal"
- content {
- excludeModule("androidx.room", "room-compiler")
- }
- }
- }
+ $repositoriesBlock
%s
diff --git a/testutils/testutils-gradle-plugin/src/main/java/androidx/testutils/gradle/ProjectSetupRule.kt b/testutils/testutils-gradle-plugin/src/main/java/androidx/testutils/gradle/ProjectSetupRule.kt
index 170d5eb..06509a9 100644
--- a/testutils/testutils-gradle-plugin/src/main/java/androidx/testutils/gradle/ProjectSetupRule.kt
+++ b/testutils/testutils-gradle-plugin/src/main/java/androidx/testutils/gradle/ProjectSetupRule.kt
@@ -21,7 +21,6 @@
import org.junit.runner.Description
import org.junit.runners.model.Statement
import java.io.File
-import java.lang.IllegalStateException
import java.util.Properties
/**
@@ -43,13 +42,22 @@
val gradlePropertiesFile: File
get() = File(rootDir, "gradle.properties")
+ /**
+ * Combined list of local build repo and remote repositories (prebuilts etc).
+ * Local build repo is the first in line to ensure it is prioritized.
+ */
+ val allRepositoryPaths: List<String> by lazy {
+ listOf(props.localSupportRepo) + props.repositoryUrls
+ }
+
private val repositories: String
- get() = """
- repositories {
- maven { url "${props.prebuiltsRoot}/androidx/external" }
- maven { url "${props.prebuiltsRoot}/androidx/internal" }
+ get() = buildString {
+ appendLine("repositories {")
+ props.repositoryUrls.forEach {
+ appendLine(" maven { url '$it' }")
}
- """.trimIndent()
+ appendLine("}")
+ }
val androidProject: String
get() = """
@@ -117,7 +125,8 @@
val kotlinStblib: String,
val rootProjectPath: String,
val localSupportRepo: String,
- val agpDependency: String
+ val agpDependency: String,
+ val repositoryUrls: List<String>
) {
companion object {
fun load(): ProjectProps {
@@ -134,7 +143,8 @@
kotlinStblib = properties.getProperty("kotlinStdlib"),
rootProjectPath = properties.getProperty("rootProjectPath"),
localSupportRepo = properties.getProperty("localSupportRepo"),
- agpDependency = properties.getProperty("agpDependency")
+ agpDependency = properties.getProperty("agpDependency"),
+ repositoryUrls = properties.getProperty("repositoryUrls").split(",")
)
}
}