aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2023-11-23 13:27:12 +0100
committerLinnea Gräf <nea@nea.moe>2023-11-23 13:27:12 +0100
commitdb56cfdb57c481de8c833a1a53b7e9f9cdae82c0 (patch)
treefe74dd40f2b8f74e9e5d71d684372dcd1ab2600b
downloadgradle-init-scripts-db56cfdb57c481de8c833a1a53b7e9f9cdae82c0.tar.gz
gradle-init-scripts-db56cfdb57c481de8c833a1a53b7e9f9cdae82c0.tar.bz2
gradle-init-scripts-db56cfdb57c481de8c833a1a53b7e9f9cdae82c0.zip
Initial commit
-rw-r--r--README.md10
-rw-r--r--addNeaMoeMavenRepo.init.gradle.kts23
-rw-r--r--alwaysUseGpg.init.gradle.kts20
-rw-r--r--installMinecraft.init.gradle.kts49
4 files changed, 102 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..2a8255b
--- /dev/null
+++ b/README.md
@@ -0,0 +1,10 @@
+# Gradle Init Scripts
+
+Collection of useful gradle configuration snippets / init scripts.
+
+To use one of these init scripts, place it into `$GRADLE_HOME/init.d` (typically `~/.gradle/init.d/`). This folder will not exist by default.
+
+Note that these might break on older versions of gradle, so if you use old gradle versions and get compilation errors, rename the offending scripts to end with `.disabled` or something similar while you work on those projects. That being said, most of them should work on gradle 6+.
+
+If you want to specify a gradle property globally you can do so in `$GRADLE_HOME/gradle.properties` (typically `~/.gradle/gradle.properties`).
+
diff --git a/addNeaMoeMavenRepo.init.gradle.kts b/addNeaMoeMavenRepo.init.gradle.kts
new file mode 100644
index 0000000..e049550
--- /dev/null
+++ b/addNeaMoeMavenRepo.init.gradle.kts
@@ -0,0 +1,23 @@
+allprojects {
+ afterEvaluate {
+ extensions.findByType<PublishingExtension>()?.repositories {
+ maven("https://repo.nea.moe/mirror") {
+ name = "neamoeMirror"
+ credentials(PasswordCredentials::class)
+ authentication {
+ create<BasicAuthentication>("basic")
+ }
+ }
+ maven("https://repo.nea.moe/releases") {
+ name = "neamoeReleases"
+ credentials(PasswordCredentials::class)
+ authentication {
+ create<BasicAuthentication>("basic")
+ }
+ }
+ }
+ }
+}
+
+
+
diff --git a/alwaysUseGpg.init.gradle.kts b/alwaysUseGpg.init.gradle.kts
new file mode 100644
index 0000000..8a4250b
--- /dev/null
+++ b/alwaysUseGpg.init.gradle.kts
@@ -0,0 +1,20 @@
+/**
+ * Configures gradles signing plugin to use the gpg command instead of gradle properties for keys.
+ * Requires you to set global gradle properties like so:
+ * ```
+ * signing.gnupg.executable=gpg
+ * signing.gnupg.useLegacyGpg=true
+ * signing.gnupg.keyName=AA563E93EB628D91
+ * ```
+ *
+ * You can get the keyname by running `gpg --list-secret-keys --keyid-format long`. The id you want here is a signing key (it will have a `S` inside of the `[S]` brackets.). Usually you will want to sign with a subkey (indicated by `ssb` at the beginning of the line).
+ */
+
+
+allprojects {
+ afterEvaluate {
+ extensions.findByType<SigningExtension>()?.run {
+ useGpgCmd()
+ }
+ }
+}
diff --git a/installMinecraft.init.gradle.kts b/installMinecraft.init.gradle.kts
new file mode 100644
index 0000000..a61df85
--- /dev/null
+++ b/installMinecraft.init.gradle.kts
@@ -0,0 +1,49 @@
+/**
+ * Install a mod into your minecraft mod folder using a gradle task from any mod you are editing.
+ * This requires you to set the global property `minecraft.modfolder` in your global gradle.properties.
+ * Afterwards you can run `./gradlew installToMinecraft` (or ./gradlew :subproject:installToMinecraft)
+ * to install a mod into your minecraft mod folder while deleting old versions of that mod. This isn't
+ * based on mod ids, but instead on archiveBaseName, so you will need to have a jar task that behaves
+ * normally.
+ * Will only work if it detects architectury loom, fabric loom, essentials loom, forge gradle or unimined.
+ * Will prefer a remapJar task, or otherwise use the shadowJar or jar tasks (for forge gradle).
+ */
+
+
+allprojects {
+ this.afterEvaluate {
+ if (!listOf(
+ "gg.essential.loom",
+ "cc.polyfrost.loom",
+ "dev.architectury.loom",
+ "fabric-loom",
+ "net.minecraftforge.gradle.tweaker-client",
+ "net.minecraftforge.gradle.forge",
+ "xyz.wagyourtail.unimined"
+ ).any { plugins.hasPlugin(it) }
+ ) {
+ return@afterEvaluate
+ }
+ val toInstall = listOf("remapJar", "shadowJar", "jar").mapNotNull {
+ tasks.findByName(it)
+ }.filterIsInstance<org.gradle.jvm.tasks.Jar>().firstOrNull()
+ val targetDirectory = File(project.findProperty("minecraft.modfolder")!!)
+ if (toInstall != null) {
+ tasks.create("installToMinecraft") {
+ dependsOn(toInstall)
+ doLast {
+ val modJar = toInstall.archiveFile.get().asFile
+ targetDirectory.listFiles()
+ .filter {
+ it.name.startsWith(toInstall.archiveBaseName.get())
+ }
+ .forEach {
+ it.delete()
+ }
+ modJar.copyTo(targetDirectory.resolve(modJar.name))
+ println("Installed $modJar to $targetDirectory")
+ }
+ }
+ }
+}
+}