mirror of
https://github.com/tadfisher/gradle2nix.git
synced 2026-01-11 15:30:38 -05:00
Fix dependency resolution for plugins in buildSrc
This commit is contained in:
@@ -4,6 +4,7 @@ plugins {
|
||||
kotlin("jvm")
|
||||
kotlin("kapt")
|
||||
application
|
||||
idea
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -18,6 +19,11 @@ dependencies {
|
||||
implementation("com.squareup.moshi:moshi-kotlin:latest.release")
|
||||
kapt("com.squareup.moshi:moshi-kotlin-codegen:latest.release")
|
||||
implementation("com.squareup.okio:okio:latest.release")
|
||||
|
||||
testRuntimeOnly(kotlin("reflect"))
|
||||
testImplementation("org.spekframework.spek2:spek-dsl-jvm:latest.release")
|
||||
testRuntimeOnly("org.spekframework.spek2:spek-runner-junit5:latest.release")
|
||||
testImplementation("io.strikt:strikt-core:latest.release")
|
||||
}
|
||||
|
||||
application {
|
||||
@@ -30,11 +36,19 @@ application {
|
||||
.rename("plugin.*\\.jar", "plugin.jar")
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
test {
|
||||
resources {
|
||||
srcDir("$rootDir/fixtures")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks {
|
||||
(run) {
|
||||
dependsOn(installDist)
|
||||
doFirst {
|
||||
jvmArgs = listOf("-Dorg.nixos.gradle2nix.share=${installDist.get().destinationDir.resolve("share")}")
|
||||
systemProperties("org.nixos.gradle2nix.share" to installDist.get().destinationDir.resolve("share"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,9 +59,28 @@ tasks {
|
||||
}
|
||||
}
|
||||
|
||||
test {
|
||||
dependsOn(installDist)
|
||||
doFirst {
|
||||
systemProperties("org.nixos.gradle2nix.share" to installDist.get().destinationDir.resolve("share"))
|
||||
}
|
||||
useJUnitPlatform {
|
||||
includeEngines("spek2")
|
||||
}
|
||||
testLogging {
|
||||
events("passed", "skipped", "failed")
|
||||
}
|
||||
}
|
||||
|
||||
withType<KotlinCompile> {
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
}
|
||||
|
||||
idea {
|
||||
module {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
# 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.christophsturm:filepeek:0.1.2
|
||||
com.github.ajalt:clikt:2.6.0
|
||||
com.squareup.moshi:moshi-adapters:1.9.2
|
||||
com.squareup.moshi:moshi-kotlin:1.9.2
|
||||
com.squareup.moshi:moshi:1.9.2
|
||||
com.squareup.okio:okio:2.6.0
|
||||
io.strikt:strikt-core:0.25.0
|
||||
org.gradle:gradle-tooling-api:6.3
|
||||
org.jetbrains.kotlin:kotlin-reflect:1.3.70
|
||||
org.jetbrains.kotlin:kotlin-stdlib-common:1.3.70
|
||||
@@ -13,4 +15,6 @@ org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.70
|
||||
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.70
|
||||
org.jetbrains.kotlin:kotlin-stdlib:1.3.70
|
||||
org.jetbrains:annotations:13.0
|
||||
org.opentest4j:opentest4j:1.2.0
|
||||
org.slf4j:slf4j-api:2.0.0-alpha1
|
||||
org.spekframework.spek2:spek-dsl-jvm:2.0.10
|
||||
|
||||
@@ -1,18 +1,31 @@
|
||||
# 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.christophsturm:filepeek:0.1.2
|
||||
com.github.ajalt:clikt:2.6.0
|
||||
com.squareup.moshi:moshi-adapters:1.9.2
|
||||
com.squareup.moshi:moshi-kotlin:1.9.2
|
||||
com.squareup.moshi:moshi:1.9.2
|
||||
com.squareup.okio:okio:2.6.0
|
||||
io.github.classgraph:classgraph:4.8.37
|
||||
io.strikt:strikt-core:0.25.0
|
||||
net.swiftzer.semver:semver:1.1.1
|
||||
org.apiguardian:apiguardian-api:1.1.0
|
||||
org.gradle:gradle-tooling-api:6.3
|
||||
org.jetbrains.kotlin:kotlin-reflect:1.3.70
|
||||
org.jetbrains.kotlin:kotlin-stdlib-common:1.3.70
|
||||
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.70
|
||||
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.70
|
||||
org.jetbrains.kotlin:kotlin-stdlib:1.3.70
|
||||
org.jetbrains.kotlin:kotlin-reflect:1.3.71
|
||||
org.jetbrains.kotlin:kotlin-stdlib-common:1.3.71
|
||||
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.71
|
||||
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.71
|
||||
org.jetbrains.kotlin:kotlin-stdlib:1.3.71
|
||||
org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.3.3
|
||||
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.5
|
||||
org.jetbrains:annotations:13.0
|
||||
org.junit.platform:junit-platform-commons:1.6.0
|
||||
org.junit.platform:junit-platform-engine:1.6.0
|
||||
org.junit:junit-bom:5.6.0
|
||||
org.opentest4j:opentest4j:1.2.0
|
||||
org.slf4j:slf4j-api:2.0.0-alpha1
|
||||
org.slf4j:slf4j-simple:2.0.0-alpha1
|
||||
org.spekframework.spek2:spek-dsl-jvm:2.0.10
|
||||
org.spekframework.spek2:spek-runner-junit5:2.0.10
|
||||
org.spekframework.spek2:spek-runtime-jvm:2.0.10
|
||||
|
||||
@@ -24,7 +24,6 @@ fun ProjectConnection.getBuildModel(config: Config, path: String): DefaultBuild
|
||||
if (config.gradleArgs != null) addArguments(config.gradleArgs)
|
||||
if (path.isNotEmpty()) addArguments("--project-dir=$path")
|
||||
if (!config.quiet) {
|
||||
setColorOutput(true)
|
||||
setStandardOutput(System.err)
|
||||
setStandardError(System.err)
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import com.github.ajalt.clikt.parameters.options.default
|
||||
import com.github.ajalt.clikt.parameters.options.flag
|
||||
import com.github.ajalt.clikt.parameters.options.multiple
|
||||
import com.github.ajalt.clikt.parameters.options.option
|
||||
import com.github.ajalt.clikt.parameters.options.split
|
||||
import com.github.ajalt.clikt.parameters.options.validate
|
||||
import com.github.ajalt.clikt.parameters.types.file
|
||||
import com.squareup.moshi.Moshi
|
||||
@@ -55,7 +54,7 @@ class Main : CliktCommand(
|
||||
private val includes: List<File> by option("--include", "-i",
|
||||
metavar = "DIR",
|
||||
help = "Add an additional project to include")
|
||||
.file(exists = true, fileOkay = false, folderOkay = true, readable = true)
|
||||
.file(mustExist = true, canBeFile = false, canBeDir = true, mustBeReadable = true)
|
||||
.multiple()
|
||||
.validate { files ->
|
||||
val failures = files.filterNot { it.isProjectRoot() }
|
||||
@@ -79,12 +78,12 @@ class Main : CliktCommand(
|
||||
}
|
||||
}
|
||||
|
||||
private val outDir: File? by option("--out-dir", "-o",
|
||||
val outDir: File? by option("--out-dir", "-o",
|
||||
metavar = "DIR",
|
||||
help = "Path to write generated files (default: PROJECT-DIR)")
|
||||
.file(fileOkay = false, folderOkay = true)
|
||||
.file(canBeFile = false, canBeDir = true)
|
||||
|
||||
private val envFile: String by option("--env", "-e",
|
||||
val envFile: String by option("--env", "-e",
|
||||
metavar = "FILENAME",
|
||||
help = "Prefix for environment files (.json and .nix)")
|
||||
.default("gradle-env")
|
||||
@@ -105,8 +104,11 @@ class Main : CliktCommand(
|
||||
}
|
||||
}
|
||||
|
||||
// Visible for testing
|
||||
lateinit var config: Config
|
||||
|
||||
override fun run() {
|
||||
val config = Config(
|
||||
config = Config(
|
||||
gradleVersion,
|
||||
gradleArgs,
|
||||
configurations,
|
||||
|
||||
19
app/src/test/kotlin/org/nixos/gradle2nix/BuildSrcTest.kt
Normal file
19
app/src/test/kotlin/org/nixos/gradle2nix/BuildSrcTest.kt
Normal file
@@ -0,0 +1,19 @@
|
||||
package org.nixos.gradle2nix
|
||||
|
||||
import org.spekframework.spek2.Spek
|
||||
import org.spekframework.spek2.style.specification.describe
|
||||
import strikt.api.expectThat
|
||||
import strikt.assertions.containsKey
|
||||
|
||||
object BuildSrcTest : Spek({
|
||||
fixture("buildsrc/plugin-in-buildsrc/kotlin")
|
||||
val fixture: Fixture by memoized()
|
||||
|
||||
describe("project with plugin in buildSrc") {
|
||||
fixture.run()
|
||||
|
||||
it("should include buildSrc in gradle env", timeout = 0) {
|
||||
expectThat(fixture.env()).containsKey("buildSrc")
|
||||
}
|
||||
}
|
||||
})
|
||||
57
app/src/test/kotlin/org/nixos/gradle2nix/TestUtil.kt
Normal file
57
app/src/test/kotlin/org/nixos/gradle2nix/TestUtil.kt
Normal file
@@ -0,0 +1,57 @@
|
||||
package org.nixos.gradle2nix
|
||||
|
||||
import com.squareup.moshi.Moshi
|
||||
import com.squareup.moshi.Types
|
||||
import okio.buffer
|
||||
import okio.source
|
||||
import org.spekframework.spek2.dsl.Root
|
||||
import strikt.api.expectThat
|
||||
import strikt.assertions.exists
|
||||
import strikt.assertions.isNotNull
|
||||
import strikt.assertions.toPath
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
|
||||
private val moshi = Moshi.Builder().build()
|
||||
|
||||
class Fixture(val project: Path) {
|
||||
private val app = Main()
|
||||
|
||||
fun run(vararg args: String) {
|
||||
app.main(args.toList() + project.toString())
|
||||
}
|
||||
|
||||
fun env(): Map<String, NixGradleEnv> {
|
||||
val file = (app.outDir ?: project.toFile()).resolve("${app.envFile}.json")
|
||||
expectThat(file).toPath().exists()
|
||||
val env = file.source().buffer().use { source ->
|
||||
moshi
|
||||
.adapter<Map<String, NixGradleEnv>>(
|
||||
Types.newParameterizedType(Map::class.java, String::class.java, NixGradleEnv::class.java)
|
||||
).fromJson(source)
|
||||
}
|
||||
expectThat(env).isNotNull()
|
||||
return env!!
|
||||
}
|
||||
}
|
||||
|
||||
fun Root.fixture(name: String) {
|
||||
val fixture by memoized(
|
||||
factory = {
|
||||
val url = checkNotNull(Thread.currentThread().contextClassLoader.getResource(name)?.toURI()) {
|
||||
"$name: No test fixture found"
|
||||
}
|
||||
val fixtureRoot = Paths.get(url)
|
||||
val dest = createTempDir("gradle2nix").toPath()
|
||||
val src = checkNotNull(fixtureRoot.takeIf { Files.exists(it) }) {
|
||||
"$name: Test fixture not found: $fixtureRoot"
|
||||
}
|
||||
src.toFile().copyRecursively(dest.toFile())
|
||||
Fixture(dest)
|
||||
},
|
||||
destructor = {
|
||||
it.project.toFile().deleteRecursively()
|
||||
}
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user