mirror of
https://github.com/tadfisher/gradle2nix.git
synced 2026-01-11 23:40:37 -05:00
First stab
This commit is contained in:
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