mirror of
https://github.com/tadfisher/gradle2nix.git
synced 2026-01-11 15:30:38 -05:00
Generate buildSrc env
This commit is contained in:
@@ -13,7 +13,9 @@ application {
|
|||||||
applicationName = "gradle2nix"
|
applicationName = "gradle2nix"
|
||||||
applicationDefaultJvmArgs += "-Dorg.nixos.gradle2nix.initScript=@APP_HOME@/gradle/init.gradle"
|
applicationDefaultJvmArgs += "-Dorg.nixos.gradle2nix.initScript=@APP_HOME@/gradle/init.gradle"
|
||||||
applicationDistribution
|
applicationDistribution
|
||||||
.from(tasks.getByPath(":plugin:shadowJar"))
|
.from(
|
||||||
|
tasks.getByPath(":plugin:shadowJar"),
|
||||||
|
project(":plugin").file("src/main/resources/init.gradle"))
|
||||||
.into("gradle")
|
.into("gradle")
|
||||||
.rename("plugin.*\\.jar", "plugin.jar")
|
.rename("plugin.*\\.jar", "plugin.jar")
|
||||||
}
|
}
|
||||||
|
|||||||
2
app/src/dist/gradle/init.gradle
vendored
2
app/src/dist/gradle/init.gradle
vendored
@@ -1,3 +1,5 @@
|
|||||||
|
package org.nixos.gradle2nix
|
||||||
|
|
||||||
initscript {
|
initscript {
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath files("plugin.jar")
|
classpath files("plugin.jar")
|
||||||
|
|||||||
@@ -40,6 +40,11 @@ tasks {
|
|||||||
kotlinDsl = true
|
kotlinDsl = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
register("gradle2nixTest", Test::class) {
|
||||||
|
dependsOn(gradleTest)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
gradleTestGenerator {
|
gradleTestGenerator {
|
||||||
dependsOn(shadowJar)
|
dependsOn(shadowJar)
|
||||||
doLast {
|
doLast {
|
||||||
|
|||||||
3
plugin/src/gradleTest/projectWithBuildSrc/build.gradle
Normal file
3
plugin/src/gradleTest/projectWithBuildSrc/build.gradle
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
task runGradleTest {
|
||||||
|
dependsOn 'nixGradleEnv'
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
tasks.register("runGradleTest") {
|
||||||
|
dependsOn("nixGradleEnv")
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
apply plugin: "java"
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
jcenter()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation("com.squareup.okio:okio:2.2.2")
|
||||||
|
implementation("com.squareup.moshi:moshi:1.8.0")
|
||||||
|
}
|
||||||
@@ -45,6 +45,22 @@ open class Gradle2NixPlugin : Plugin<Gradle> {
|
|||||||
outputDir.set(extension.outputDir)
|
outputDir.set(extension.outputDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val buildSrcDir = rootProject.projectDir.resolve("buildSrc")
|
||||||
|
if (buildSrcDir.exists() && buildSrcDir.isDirectory) {
|
||||||
|
val buildSrcEnv =
|
||||||
|
rootProject.tasks.register("nixBuildSrcEnv", NixBuildSrcEnv::class) {
|
||||||
|
dir = buildSrcDir
|
||||||
|
val buildFile = buildSrcDir.listFiles().let { files ->
|
||||||
|
files.find { it.name == "build.gradle.kts" } ?:
|
||||||
|
files.find { it.name == "build.gradle" }
|
||||||
|
}
|
||||||
|
if (buildFile != null) this.buildFile = buildFile
|
||||||
|
}
|
||||||
|
gradleEnv.configure {
|
||||||
|
dependsOn(buildSrcEnv)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val pluginEnv =
|
val pluginEnv =
|
||||||
rootProject.tasks.register("nixPluginEnv", NixPluginEnv::class, pluginRequests)
|
rootProject.tasks.register("nixPluginEnv", NixPluginEnv::class, pluginRequests)
|
||||||
gradleEnv.configure {
|
gradleEnv.configure {
|
||||||
@@ -115,6 +131,10 @@ open class Gradle2NixPlugin : Plugin<Gradle> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal val pluginJar by lazy {
|
||||||
|
File(Gradle2NixPlugin::class.java.protectionDomain.codeSource.location.toURI()).absoluteFile
|
||||||
|
}
|
||||||
|
|
||||||
internal val moshi by lazy { Moshi.Builder().build() }
|
internal val moshi by lazy { Moshi.Builder().build() }
|
||||||
|
|
||||||
open class Gradle2NixExtension(project: Project, defaultConfigurations: List<String>) {
|
open class Gradle2NixExtension(project: Project, defaultConfigurations: List<String>) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.nixos.gradle2nix
|
package org.nixos.gradle2nix
|
||||||
|
|
||||||
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.file.Directory
|
import org.gradle.api.file.Directory
|
||||||
import org.gradle.api.file.DirectoryProperty
|
import org.gradle.api.file.DirectoryProperty
|
||||||
import org.gradle.api.file.RegularFile
|
import org.gradle.api.file.RegularFile
|
||||||
@@ -67,3 +68,21 @@ internal fun RegularFileProperty.conventionCompat(
|
|||||||
apply { set(valueProvider) }
|
apply { set(valueProvider) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
internal fun Project.directoryPropertyCompat(): DirectoryProperty {
|
||||||
|
return if (versionAtLeast("5.0")) {
|
||||||
|
objects.directoryProperty()
|
||||||
|
} else {
|
||||||
|
layout.directoryProperty()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
internal fun Project.filePropertyCompat(): RegularFileProperty {
|
||||||
|
return if (versionAtLeast("5.0")) {
|
||||||
|
objects.fileProperty()
|
||||||
|
} else {
|
||||||
|
layout.fileProperty()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package org.nixos.gradle2nix
|
||||||
|
|
||||||
|
import org.gradle.api.tasks.GradleBuild
|
||||||
|
import org.gradle.api.tasks.InputDirectory
|
||||||
|
import org.gradle.api.tasks.InputFile
|
||||||
|
import org.gradle.api.tasks.Optional
|
||||||
|
import org.gradle.kotlin.dsl.configure
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
open class NixBuildSrcEnv : GradleBuild() {
|
||||||
|
init {
|
||||||
|
configure {
|
||||||
|
tasks = listOf("nixGradleEnv")
|
||||||
|
startParameter.addInitScript(writeInitScriptTo(dir.resolve("build/nix/init.gradle")))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun writeInitScriptTo(dest: File): File {
|
||||||
|
dest.parentFile.mkdirs()
|
||||||
|
dest.writeText("""
|
||||||
|
initscript {
|
||||||
|
dependencies {
|
||||||
|
classpath files("$pluginJar")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
apply plugin: org.nixos.gradle2nix.Gradle2NixPlugin
|
||||||
|
""".trimIndent())
|
||||||
|
return dest
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user