mirror of
https://github.com/tadfisher/gradle2nix.git
synced 2026-01-11 15:30:38 -05:00
Add "--project", "-p" option for resolving subprojects explicitly
Fixes #4. Also resolves #3 by excluding the local maven repo.
This commit is contained in:
@@ -2,12 +2,12 @@
|
||||
# Manual edits can break the build and are not advised.
|
||||
# This file is expected to be part of source control.
|
||||
com.github.ajalt:clikt:2.2.0
|
||||
com.squareup.moshi:moshi-adapters:1.8.0
|
||||
com.squareup.moshi:moshi-kotlin:1.8.0
|
||||
com.squareup.moshi:moshi:1.8.0
|
||||
com.squareup.moshi:moshi-adapters:1.9.1
|
||||
com.squareup.moshi:moshi-kotlin:1.9.1
|
||||
com.squareup.moshi:moshi:1.9.1
|
||||
com.squareup.okio:okio:2.4.1
|
||||
org.gradle:gradle-tooling-api:5.6.2
|
||||
org.jetbrains.kotlin:kotlin-reflect:1.3.41
|
||||
org.gradle:gradle-tooling-api:5.6.3
|
||||
org.jetbrains.kotlin:kotlin-reflect:1.3.50
|
||||
org.jetbrains.kotlin:kotlin-stdlib-common:1.3.50
|
||||
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.41
|
||||
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.41
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
# Manual edits can break the build and are not advised.
|
||||
# This file is expected to be part of source control.
|
||||
com.github.ajalt:clikt:2.2.0
|
||||
com.squareup.moshi:moshi-adapters:1.8.0
|
||||
com.squareup.moshi:moshi-kotlin:1.8.0
|
||||
com.squareup.moshi:moshi:1.8.0
|
||||
com.squareup.moshi:moshi-adapters:1.9.1
|
||||
com.squareup.moshi:moshi-kotlin:1.9.1
|
||||
com.squareup.moshi:moshi:1.9.1
|
||||
com.squareup.okio:okio:2.4.1
|
||||
org.gradle:gradle-tooling-api:5.6.2
|
||||
org.jetbrains.kotlin:kotlin-reflect:1.3.41
|
||||
org.gradle:gradle-tooling-api:5.6.3
|
||||
org.jetbrains.kotlin:kotlin-reflect:1.3.50
|
||||
org.jetbrains.kotlin:kotlin-stdlib-common:1.3.50
|
||||
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.41
|
||||
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.41
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
# Manual edits can break the build and are not advised.
|
||||
# This file is expected to be part of source control.
|
||||
com.github.ajalt:clikt:2.2.0
|
||||
com.squareup.moshi:moshi-adapters:1.8.0
|
||||
com.squareup.moshi:moshi-kotlin:1.8.0
|
||||
com.squareup.moshi:moshi:1.8.0
|
||||
com.squareup.moshi:moshi-adapters:1.9.1
|
||||
com.squareup.moshi:moshi-kotlin:1.9.1
|
||||
com.squareup.moshi:moshi:1.9.1
|
||||
com.squareup.okio:okio:2.4.1
|
||||
org.gradle:gradle-tooling-api:5.6.2
|
||||
org.jetbrains.kotlin:kotlin-reflect:1.3.41
|
||||
org.gradle:gradle-tooling-api:5.6.3
|
||||
org.jetbrains.kotlin:kotlin-reflect:1.3.50
|
||||
org.jetbrains.kotlin:kotlin-stdlib-common:1.3.50
|
||||
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.41
|
||||
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.41
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
# Manual edits can break the build and are not advised.
|
||||
# This file is expected to be part of source control.
|
||||
com.github.ajalt:clikt:2.2.0
|
||||
com.squareup.moshi:moshi-adapters:1.8.0
|
||||
com.squareup.moshi:moshi-kotlin:1.8.0
|
||||
com.squareup.moshi:moshi:1.8.0
|
||||
com.squareup.moshi:moshi-adapters:1.9.1
|
||||
com.squareup.moshi:moshi-kotlin:1.9.1
|
||||
com.squareup.moshi:moshi:1.9.1
|
||||
com.squareup.okio:okio:2.4.1
|
||||
org.gradle:gradle-tooling-api:5.6.2
|
||||
org.jetbrains.kotlin:kotlin-reflect:1.3.41
|
||||
org.gradle:gradle-tooling-api:5.6.3
|
||||
org.jetbrains.kotlin:kotlin-reflect:1.3.50
|
||||
org.jetbrains.kotlin:kotlin-stdlib-common:1.3.50
|
||||
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.41
|
||||
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.41
|
||||
|
||||
@@ -13,24 +13,18 @@ fun connect(config: Config): ProjectConnection =
|
||||
.forProjectDirectory(config.projectDir)
|
||||
.connect()
|
||||
|
||||
@Suppress("UnstableApiUsage")
|
||||
fun ProjectConnection.getBuildModel(config: Config, path: String): DefaultBuild {
|
||||
val arguments = mutableListOf(
|
||||
"--init-script=$shareDir/init.gradle",
|
||||
"-Dorg.nixos.gradle2nix.configurations='${config.configurations.joinToString(",")}'"
|
||||
)
|
||||
|
||||
if (path.isNotEmpty()) {
|
||||
arguments += "--project-dir=$path"
|
||||
}
|
||||
|
||||
return model(Build::class.java)
|
||||
.withArguments(arguments)
|
||||
.apply {
|
||||
if (!config.quiet) {
|
||||
setStandardOutput(System.err)
|
||||
setStandardError(System.err)
|
||||
}
|
||||
return model(Build::class.java).apply {
|
||||
addArguments("--init-script=$shareDir/init.gradle")
|
||||
if (path.isNotEmpty()) addArguments("--project-dir=$path")
|
||||
addJvmArguments(
|
||||
"-Dorg.nixos.gradle2nix.configurations='${config.configurations.joinToString(",")}'",
|
||||
"-Dorg.nixos.gradle2nix.subprojects='${config.subprojects.joinToString(",")}'"
|
||||
)
|
||||
if (!config.quiet) {
|
||||
setStandardOutput(System.err)
|
||||
setStandardError(System.err)
|
||||
}
|
||||
.get()
|
||||
.let { DefaultBuild(it) }
|
||||
}.get().let { DefaultBuild(it) }
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ data class Config(
|
||||
val configurations: List<String>,
|
||||
val projectDir: File,
|
||||
val includes: List<File>,
|
||||
val subprojects: List<String>,
|
||||
val buildSrc: Boolean,
|
||||
val quiet: Boolean
|
||||
) {
|
||||
@@ -55,6 +56,19 @@ class Main : CliktCommand(
|
||||
}
|
||||
}
|
||||
|
||||
private val subprojects: List<String> by option("--project", "-p",
|
||||
metavar = "PATH",
|
||||
help = "Only resolve these subproject paths, e.g. ':', or ':sub:project' (default: all projects)")
|
||||
.multiple()
|
||||
.validate { paths ->
|
||||
val failures = paths.filterNot { it.startsWith(":") }
|
||||
if (failures.isNotEmpty()) {
|
||||
val message = failures.joinToString("\n ")
|
||||
fail("Subproject paths must be absolute:\n$message\n" +
|
||||
"Paths are in the form ':parent:child'.")
|
||||
}
|
||||
}
|
||||
|
||||
private val outDir: File? by option("--out-dir", "-o",
|
||||
metavar = "DIR",
|
||||
help = "Path to write generated files (default: PROJECT-DIR)")
|
||||
@@ -82,7 +96,7 @@ class Main : CliktCommand(
|
||||
}
|
||||
|
||||
override fun run() {
|
||||
val config = Config(gradleVersion, configurations, projectDir, includes, buildSrc, quiet)
|
||||
val config = Config(gradleVersion, configurations, projectDir, includes, subprojects, buildSrc, quiet)
|
||||
val (log, _, _) = Logger(verbose = !config.quiet)
|
||||
|
||||
val paths = resolveProjects(config).map { p ->
|
||||
|
||||
@@ -45,7 +45,7 @@ allprojects {
|
||||
|
||||
tasks {
|
||||
wrapper {
|
||||
gradleVersion = "5.6.2"
|
||||
gradleVersion = "5.6.3"
|
||||
distributionType = Wrapper.DistributionType.ALL
|
||||
}
|
||||
}
|
||||
|
||||
1519
gradle-env.json
1519
gradle-env.json
File diff suppressed because it is too large
Load Diff
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.3-all.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# This is a Gradle generated file for dependency locking.
|
||||
# Manual edits can break the build and are not advised.
|
||||
# This file is expected to be part of source control.
|
||||
com.squareup.moshi:moshi:1.8.0
|
||||
com.squareup.moshi:moshi:1.9.1
|
||||
com.squareup.okio:okio:2.4.1
|
||||
org.jetbrains.kotlin:kotlin-reflect:1.3.41
|
||||
org.jetbrains.kotlin:kotlin-stdlib-common:1.3.50
|
||||
|
||||
@@ -5,4 +5,4 @@
|
||||
5.3.1
|
||||
5.4.1
|
||||
5.5.1
|
||||
5.6.2
|
||||
5.6.3
|
||||
|
||||
@@ -12,4 +12,4 @@
|
||||
5.3.1
|
||||
5.4.1
|
||||
5.5.1
|
||||
5.6.2
|
||||
5.6.3
|
||||
|
||||
@@ -10,7 +10,7 @@ org.apache.maven:maven-model:3.6.2
|
||||
org.codehaus.plexus:plexus-interpolation:1.25
|
||||
org.codehaus.plexus:plexus-utils:3.2.1
|
||||
org.eclipse.sisu:org.eclipse.sisu.inject:0.3.3
|
||||
org.gradle:gradle-tooling-api:5.6.2
|
||||
org.gradle:gradle-tooling-api:5.6.3
|
||||
org.jetbrains.kotlin:kotlin-reflect:1.3.41
|
||||
org.jetbrains.kotlin:kotlin-stdlib-common:1.3.41
|
||||
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.41
|
||||
|
||||
@@ -241,4 +241,179 @@ class SubprojectsTest {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `builds single subproject in multi-module project with kotlin dsl`() {
|
||||
root.resolve("child-a").also { it.mkdirs() }
|
||||
.resolve("build.gradle.kts").writeText("""
|
||||
plugins {
|
||||
java
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("com.squareup.okio:okio:2.2.2")
|
||||
}
|
||||
""".trimIndent())
|
||||
|
||||
root.resolve("child-b").also { it.mkdirs() }
|
||||
.resolve("build.gradle.kts").writeText("""
|
||||
plugins {
|
||||
java
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("com.squareup.moshi:moshi:1.8.0")
|
||||
}
|
||||
""".trimIndent())
|
||||
|
||||
root.resolve("settings.gradle.kts").writeText("""
|
||||
include(":child-a", ":child-b")
|
||||
""".trimIndent())
|
||||
|
||||
val model = root.buildKotlin("""
|
||||
plugins {
|
||||
java
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testImplementation("junit:junit:4.12")
|
||||
}
|
||||
""".trimIndent(),
|
||||
subprojects = listOf(":child-a"))
|
||||
|
||||
with(model.rootProject) {
|
||||
with(projectDependencies) {
|
||||
assertEquals(listOf(DefaultMaven(urls = listOf("https://jcenter.bintray.com/"))),
|
||||
repositories.maven)
|
||||
|
||||
assertArtifacts(
|
||||
jar("junit:junit:4.12"),
|
||||
pom("junit:junit:4.12"),
|
||||
jar("org.hamcrest:hamcrest-core:1.3"),
|
||||
pom("org.hamcrest:hamcrest-core:1.3"),
|
||||
pom("org.hamcrest:hamcrest-parent:1.3"),
|
||||
actual = artifacts)
|
||||
}
|
||||
|
||||
assertEquals(1, children.size)
|
||||
|
||||
with(children[0]) {
|
||||
assertEquals("child-a", name)
|
||||
assertEquals(root.resolve("child-a").toRelativeString(root), projectDir)
|
||||
|
||||
with(projectDependencies) {
|
||||
assertEquals(
|
||||
listOf(DefaultMaven(urls = listOf("https://jcenter.bintray.com/"))),
|
||||
repositories.maven
|
||||
)
|
||||
|
||||
assertArtifacts(
|
||||
jar("com.squareup.okio:okio:2.2.2"),
|
||||
pom("com.squareup.okio:okio:2.2.2"),
|
||||
jar("org.jetbrains.kotlin:kotlin-stdlib-common:1.2.60"),
|
||||
pom("org.jetbrains.kotlin:kotlin-stdlib-common:1.2.60"),
|
||||
jar("org.jetbrains.kotlin:kotlin-stdlib:1.2.60"),
|
||||
pom("org.jetbrains.kotlin:kotlin-stdlib:1.2.60"),
|
||||
jar("org.jetbrains:annotations:13.0"),
|
||||
pom("org.jetbrains:annotations:13.0"),
|
||||
actual = artifacts
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `builds single subproject in multi-module project with groovy dsl`() {
|
||||
root.resolve("child-a").also { it.mkdirs() }
|
||||
.resolve("build.gradle").writeText("""
|
||||
plugins {
|
||||
id 'java'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.squareup.okio:okio:2.2.2'
|
||||
}
|
||||
""".trimIndent())
|
||||
|
||||
root.resolve("child-b").also { it.mkdirs() }
|
||||
.resolve("build.gradle").writeText("""
|
||||
plugins {
|
||||
id 'java'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.squareup.moshi:moshi:1.8.0'
|
||||
}
|
||||
""".trimIndent())
|
||||
|
||||
root.resolve("settings.gradle").writeText("""
|
||||
include ':child-a', ':child-b'
|
||||
""".trimIndent())
|
||||
|
||||
val model = root.buildGroovy("""
|
||||
plugins {
|
||||
id 'java'
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testImplementation 'junit:junit:4.12'
|
||||
}
|
||||
""".trimIndent(),
|
||||
subprojects = listOf(":child-a"))
|
||||
|
||||
with(model.rootProject) {
|
||||
with(projectDependencies) {
|
||||
assertEquals(listOf(DefaultMaven(urls = listOf("https://jcenter.bintray.com/"))),
|
||||
repositories.maven)
|
||||
|
||||
assertArtifacts(
|
||||
jar("junit:junit:4.12"),
|
||||
pom("junit:junit:4.12"),
|
||||
jar("org.hamcrest:hamcrest-core:1.3"),
|
||||
pom("org.hamcrest:hamcrest-core:1.3"),
|
||||
pom("org.hamcrest:hamcrest-parent:1.3"),
|
||||
actual = artifacts)
|
||||
}
|
||||
|
||||
assertEquals(1, children.size)
|
||||
|
||||
with(children[0]) {
|
||||
assertEquals("child-a", name)
|
||||
assertEquals(root.resolve("child-a").toRelativeString(root), projectDir)
|
||||
|
||||
with(projectDependencies) {
|
||||
assertEquals(
|
||||
listOf(DefaultMaven(urls = listOf("https://jcenter.bintray.com/"))),
|
||||
repositories.maven
|
||||
)
|
||||
|
||||
assertArtifacts(
|
||||
jar("com.squareup.okio:okio:2.2.2"),
|
||||
pom("com.squareup.okio:okio:2.2.2"),
|
||||
jar("org.jetbrains.kotlin:kotlin-stdlib-common:1.2.60"),
|
||||
pom("org.jetbrains.kotlin:kotlin-stdlib-common:1.2.60"),
|
||||
jar("org.jetbrains.kotlin:kotlin-stdlib:1.2.60"),
|
||||
pom("org.jetbrains.kotlin:kotlin-stdlib:1.2.60"),
|
||||
jar("org.jetbrains:annotations:13.0"),
|
||||
pom("org.jetbrains:annotations:13.0"),
|
||||
actual = artifacts
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,28 +23,41 @@ private fun File.initscript() = resolve("init.gradle").also {
|
||||
}
|
||||
}
|
||||
|
||||
fun File.buildGroovy(script: String): DefaultBuild {
|
||||
fun File.buildGroovy(
|
||||
script: String,
|
||||
configurations: List<String> = emptyList(),
|
||||
subprojects: List<String> = emptyList()
|
||||
): DefaultBuild {
|
||||
resolve("build.gradle").writeText(script)
|
||||
return build()
|
||||
return build(configurations, subprojects)
|
||||
}
|
||||
|
||||
fun File.buildKotlin(script: String): DefaultBuild {
|
||||
fun File.buildKotlin(
|
||||
script: String,
|
||||
configurations: List<String> = emptyList(),
|
||||
subprojects: List<String> = emptyList()
|
||||
): DefaultBuild {
|
||||
resolve("build.gradle.kts").writeText(script)
|
||||
return build()
|
||||
return build(configurations, subprojects)
|
||||
}
|
||||
|
||||
private fun File.build(): DefaultBuild {
|
||||
private fun File.build(
|
||||
configurations: List<String>,
|
||||
subprojects: List<String>
|
||||
): DefaultBuild {
|
||||
return GradleConnector.newConnector()
|
||||
.useGradleVersion(System.getProperty("compat.gradle.version"))
|
||||
.forProjectDirectory(this)
|
||||
.connect()
|
||||
.model(Build::class.java)
|
||||
.withArguments(
|
||||
"--init-script=${initscript()}",
|
||||
"--stacktrace"
|
||||
)
|
||||
.setStandardOutput(System.out)
|
||||
.setStandardError(System.out)
|
||||
.model(Build::class.java).apply {
|
||||
addArguments("--init-script=${initscript()}", "--stacktrace")
|
||||
addJvmArguments(
|
||||
"-Dorg.nixos.gradle2nix.configurations=${configurations.joinToString(",")}",
|
||||
"-Dorg.nixos.gradle2nix.subprojects=${subprojects.joinToString(",")}"
|
||||
)
|
||||
setStandardOutput(System.out)
|
||||
setStandardError(System.out)
|
||||
}
|
||||
.get()
|
||||
.let { DefaultBuild(it) }
|
||||
}
|
||||
@@ -67,8 +80,8 @@ private fun artifact(notation: String, sha256: String, type: String): DefaultArt
|
||||
)
|
||||
}
|
||||
|
||||
private fun artifactEquals(expected: DefaultArtifact, actual: DefaultArtifact): Boolean {
|
||||
return with (expected) {
|
||||
private fun artifactEquals(expected: DefaultArtifact, actual: DefaultArtifact?): Boolean {
|
||||
return actual != null && with (expected) {
|
||||
groupId == actual.groupId &&
|
||||
artifactId == actual.artifactId &&
|
||||
version == actual.version &&
|
||||
@@ -82,24 +95,24 @@ fun assertArtifacts(vararg expected: DefaultArtifact, actual: List<DefaultArtifa
|
||||
val mismatches = mutableListOf<Mismatch>()
|
||||
val remaining = mutableListOf<DefaultArtifact>().also { it.addAll(actual) }
|
||||
expected.forEachIndexed { i: Int, exp: DefaultArtifact ->
|
||||
val act = actual[i]
|
||||
val act = actual.elementAtOrNull(i)
|
||||
if (!artifactEquals(exp, act)) {
|
||||
mismatches += Mismatch(i, exp, act)
|
||||
} else {
|
||||
} else if (act != null) {
|
||||
remaining -= act
|
||||
}
|
||||
}
|
||||
assertTrue(mismatches.isEmpty() && remaining.isEmpty(), """
|
||||
Artifact mismatches:
|
||||
${mismatches.joinToString("\n ", prefix = " ")}
|
||||
${mismatches.joinToString("\n ", prefix = " ")}
|
||||
|
||||
Missing artifacts:
|
||||
${remaining.joinToString("\n ", prefix = " ")}
|
||||
${remaining.joinToString("\n ", prefix = " ")}
|
||||
""")
|
||||
}
|
||||
|
||||
data class Mismatch(
|
||||
val index: Int,
|
||||
val expected: DefaultArtifact,
|
||||
val actual: DefaultArtifact
|
||||
val actual: DefaultArtifact?
|
||||
)
|
||||
|
||||
@@ -12,7 +12,7 @@ class WrapperTest {
|
||||
@Test
|
||||
fun `resolves gradle version from wrapper configuration`() {
|
||||
val model = root.buildKotlin("""
|
||||
tasks.wrapper {
|
||||
tasks.withType<org.gradle.api.tasks.wrapper.Wrapper> {
|
||||
gradleVersion = "5.5.1"
|
||||
}
|
||||
""".trimIndent())
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.nixos.gradle2nix
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.artifacts.ArtifactRepositoryContainer
|
||||
import org.gradle.api.artifacts.dsl.RepositoryHandler
|
||||
import org.gradle.api.artifacts.repositories.MavenArtifactRepository
|
||||
import org.gradle.api.internal.GradleInternal
|
||||
@@ -14,21 +15,26 @@ import org.gradle.tooling.provider.model.ToolingModelBuilder
|
||||
import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
|
||||
import org.gradle.util.GradleVersion
|
||||
import java.net.URL
|
||||
import java.util.*
|
||||
import org.nixos.gradle2nix.Gradle as NixGradle
|
||||
import org.nixos.gradle2nix.Project as NixProject
|
||||
import java.util.Locale
|
||||
|
||||
@Suppress("unused")
|
||||
open class Gradle2NixPlugin : Plugin<Gradle> {
|
||||
override fun apply(gradle: Gradle) {
|
||||
val configurationNames: List<String> =
|
||||
System.getProperty("org.nixos.gradle2nix.configurations")?.split(",") ?: emptyList()
|
||||
val configurationNames: List<String> = System.getProperty("org.nixos.gradle2nix.configurations")
|
||||
?.takeIf { it.isNotEmpty() }
|
||||
?.split(",")
|
||||
?: emptyList()
|
||||
|
||||
val subprojects: List<String> = System.getProperty("org.nixos.gradle2nix.subprojects")
|
||||
?.takeIf { it.isNotEmpty() }
|
||||
?.split(",")
|
||||
?: emptyList()
|
||||
|
||||
val pluginRequests = collectPlugins(gradle)
|
||||
|
||||
gradle.projectsLoaded {
|
||||
rootProject.serviceOf<ToolingModelBuilderRegistry>()
|
||||
.register(NixToolingModelBuilder(configurationNames, pluginRequests))
|
||||
.register(NixToolingModelBuilder(configurationNames, subprojects, pluginRequests))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +53,7 @@ open class Gradle2NixPlugin : Plugin<Gradle> {
|
||||
|
||||
private class NixToolingModelBuilder(
|
||||
private val explicitConfigurations: List<String>,
|
||||
private val explicitSubprojects: List<String>,
|
||||
private val pluginRequests: List<PluginRequest>
|
||||
) : ToolingModelBuilder {
|
||||
override fun canBuild(modelName: String): Boolean {
|
||||
@@ -58,7 +65,7 @@ private class NixToolingModelBuilder(
|
||||
DefaultBuild(
|
||||
gradle = buildGradle(),
|
||||
pluginDependencies = plugins,
|
||||
rootProject = buildProject(explicitConfigurations, plugins),
|
||||
rootProject = buildProject(explicitConfigurations, explicitSubprojects, plugins),
|
||||
includedBuilds = includedBuilds()
|
||||
)
|
||||
}
|
||||
@@ -97,6 +104,7 @@ private fun Project.includedBuilds(): List<DefaultIncludedBuild> =
|
||||
|
||||
private fun Project.buildProject(
|
||||
explicitConfigurations: List<String>,
|
||||
explicitSubprojects: List<String>,
|
||||
plugins: DefaultDependencies
|
||||
): DefaultProject =
|
||||
DefaultProject(
|
||||
@@ -106,7 +114,9 @@ private fun Project.buildProject(
|
||||
projectDir = projectDir.toRelativeString(rootProject.projectDir),
|
||||
buildscriptDependencies = buildscriptDependencies(plugins),
|
||||
projectDependencies = projectDependencies(explicitConfigurations),
|
||||
children = childProjects.values.map { it.buildProject(explicitConfigurations, plugins) }
|
||||
children = subprojects
|
||||
.filter { explicitSubprojects.isEmpty() || it.path in explicitSubprojects }
|
||||
.map { it.buildProject(explicitConfigurations, emptyList(), plugins) }
|
||||
)
|
||||
|
||||
private fun Project.buildscriptDependencies(plugins: DefaultDependencies): DefaultDependencies =
|
||||
@@ -146,9 +156,14 @@ private fun fetchDistSha256(url: String): String {
|
||||
|
||||
private val nativePlatformJarRegex = Regex("""native-platform-([\d.]+)\.jar""")
|
||||
|
||||
private val excludedRepoNames = setOf(
|
||||
"Embedded Kotlin Repository",
|
||||
ArtifactRepositoryContainer.DEFAULT_MAVEN_LOCAL_REPO_NAME
|
||||
)
|
||||
|
||||
internal fun RepositoryHandler.repositories() = DefaultRepositories(
|
||||
maven = filterIsInstance<MavenArtifactRepository>()
|
||||
.filterNot { it.name == "Embedded Kotlin Repository" }
|
||||
.filter { it.name !in excludedRepoNames }
|
||||
.map { repo ->
|
||||
DefaultMaven(listOf(repo.url.toString()) + repo.artifactUrls.map { it.toString() })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user