mirror of
https://github.com/tadfisher/gradle2nix.git
synced 2026-01-11 15:30:38 -05:00
First stab
This commit is contained in:
45
app/build.gradle.kts
Normal file
45
app/build.gradle.kts
Normal file
@@ -0,0 +1,45 @@
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
plugins {
|
||||
kotlin("jvm") version "1.3.21"
|
||||
application
|
||||
}
|
||||
|
||||
group = "org.nixos"
|
||||
version = "1.0.0-SNAPSHOT"
|
||||
|
||||
application {
|
||||
mainClassName = "org.nixos.gradle2nix.MainKt"
|
||||
applicationName = "gradle2nix"
|
||||
applicationDefaultJvmArgs += "-Dorg.nixos.gradle2nix.initScript=@APP_HOME@/gradle/init.gradle"
|
||||
applicationDistribution
|
||||
.from(tasks.getByPath(":plugin:shadowJar"))
|
||||
.into("gradle")
|
||||
.rename("plugin.*\\.jar", "plugin.jar")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(kotlin("stdlib-jdk8"))
|
||||
implementation("org.gradle:gradle-tooling-api:${gradle.gradleVersion}")
|
||||
implementation("com.github.ajalt:clikt:1.7.0")
|
||||
}
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
maven { url = uri("https://repo.gradle.org/gradle/libs-releases") }
|
||||
}
|
||||
|
||||
tasks {
|
||||
val startScripts by existing(CreateStartScripts::class)
|
||||
startScripts {
|
||||
doLast {
|
||||
unixScript.writeText(unixScript.readText().replace("@APP_HOME@", "\$APP_HOME"))
|
||||
windowsScript.writeText(windowsScript.readText().replace("@APP_HOME@", "%APP_HOME%"))
|
||||
}
|
||||
}
|
||||
withType<KotlinCompile> {
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
}
|
||||
}
|
||||
7
app/src/dist/gradle/init.gradle
vendored
Normal file
7
app/src/dist/gradle/init.gradle
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
initscript {
|
||||
dependencies {
|
||||
classpath files("plugin.jar")
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: org.nixos.gradle2nix.Gradle2NixPlugin
|
||||
45
app/src/main/kotlin/org/nixos/gradle2nix/GradleRunner.kt
Normal file
45
app/src/main/kotlin/org/nixos/gradle2nix/GradleRunner.kt
Normal file
@@ -0,0 +1,45 @@
|
||||
package org.nixos.gradle2nix
|
||||
|
||||
import org.gradle.tooling.GradleConnector
|
||||
import java.io.File
|
||||
|
||||
class GradleRunner(
|
||||
private val projectDir: File,
|
||||
private val useWrapper: Boolean,
|
||||
private val gradleVersion: String?,
|
||||
private val configurations: List<String>
|
||||
) {
|
||||
companion object {
|
||||
val initScript: String = System.getProperty("org.nixos.gradle2nix.initScript")
|
||||
}
|
||||
|
||||
fun runGradle() {
|
||||
GradleConnector.newConnector()
|
||||
.apply {
|
||||
if (useWrapper) {
|
||||
useBuildDistribution()
|
||||
} else if (gradleVersion != null) {
|
||||
useGradleVersion(gradleVersion)
|
||||
}
|
||||
}
|
||||
.forProjectDirectory(projectDir)
|
||||
.connect()
|
||||
.use { connection ->
|
||||
connection.newBuild()
|
||||
.withArguments("--init-script", initScript)
|
||||
.apply {
|
||||
if (configurations.isNotEmpty()) {
|
||||
withArguments(
|
||||
"-Dorg.nixos.gradle2nix.configurations=${configurations.joinToString(
|
||||
","
|
||||
)}"
|
||||
)
|
||||
}
|
||||
}
|
||||
.forTasks("nixGradleEnv")
|
||||
.setStandardOutput(System.out)
|
||||
.setStandardError(System.err)
|
||||
.run()
|
||||
}
|
||||
}
|
||||
}
|
||||
25
app/src/main/kotlin/org/nixos/gradle2nix/Main.kt
Normal file
25
app/src/main/kotlin/org/nixos/gradle2nix/Main.kt
Normal file
@@ -0,0 +1,25 @@
|
||||
package org.nixos.gradle2nix
|
||||
|
||||
import com.github.ajalt.clikt.core.CliktCommand
|
||||
import com.github.ajalt.clikt.parameters.arguments.argument
|
||||
import com.github.ajalt.clikt.parameters.arguments.defaultLazy
|
||||
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.types.file
|
||||
import java.io.File
|
||||
|
||||
class Main : CliktCommand() {
|
||||
val wrapper: Boolean by option(help = "Use the project's gradle wrapper for building").flag()
|
||||
val gradleVersion: String? by option(help = "Use a specific Gradle version")
|
||||
val configurations: List<String> by option(help = "Project configuration(s)").multiple()
|
||||
val projectDir: File by argument(help = "Path to the project root")
|
||||
.file(exists = true, fileOkay = false, folderOkay = true, readable = true)
|
||||
.defaultLazy { File(".") }
|
||||
|
||||
override fun run() {
|
||||
GradleRunner(projectDir, wrapper, gradleVersion, configurations).runGradle()
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) = Main().main(args)
|
||||
Reference in New Issue
Block a user