Skip to content

Commit

Permalink
Several more changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Deftu committed Feb 13, 2024
1 parent b9cb0eb commit 9e636eb
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 33 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ kotlin.code.style=official

# Project properties
project.name=gradle-toolkit
project.version=1.22.3
project.version=1.23.0
project.group=dev.deftu.gradle
10 changes: 8 additions & 2 deletions src/main/kotlin/dev/deftu/gradle/tools/java.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ tasks.withType<JavaCompile> {
}

fun set(version: Int) {
if (version > 9) {
tasks.withType<JavaCompile> {
tasks.withType<JavaCompile> {
targetCompatibility = version.toString()

if (version > 9) {
options.release.set(version)
}
}
Expand All @@ -38,6 +40,10 @@ val javaVersion = floor(propertyOr("java.version", if (mcData.present) {
} else {
version
}.substringBefore(".")
}.let { version ->
Regex("[^0-9]").replace(version, "").ifEmpty {
throw IllegalArgumentException("Invalid java version: $version")
}
}.toDouble()).toInt()
if (javaVersion != 0) {
set(javaVersion)
Expand Down
4 changes: 4 additions & 0 deletions src/main/kotlin/dev/deftu/gradle/tools/kotlin.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ val javaVersion = floor(propertyOr("java.version", if (mcData.present) {
} else {
version
}.substringBefore(".")
}.let { version ->
Regex("[^0-9]").replace(version, "").ifEmpty {
throw IllegalArgumentException("Invalid java version: $version")
}
}.toDouble()).toInt()
if (javaVersion != 0) {
set(javaVersion)
Expand Down
36 changes: 12 additions & 24 deletions src/main/kotlin/dev/deftu/gradle/tools/maven-publishing.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import dev.deftu.gradle.MCData
import dev.deftu.gradle.ModData
import dev.deftu.gradle.ModLoader
import dev.deftu.gradle.ProjectData
import dev.deftu.gradle.utils.getFixedSourcesJarTask
import dev.deftu.gradle.utils.isMultiversionProject
import dev.deftu.gradle.utils.*

plugins {
`maven-publish`
Expand All @@ -15,6 +14,7 @@ plugins {

val RELEASES_REPO_NAME = "DeftuReleases"
val SNAPSHOT_REPO_NAME = "DeftuSnapshots"
val INTERNAL_REPO_NAME = "DeftuInternal"

val mcData = MCData.from(project)
val modData = ModData.from(project)
Expand Down Expand Up @@ -70,37 +70,25 @@ afterEvaluate {
repositories {
mavenLocal()

fun getPublishingUsername(): String? {
val property = project.findProperty("deftu.publishing.username")
return property?.toString() ?: System.getenv("DEFTU_PUBLISHING_USERNAME")
}

fun getPublishingPassword(): String? {
val property = project.findProperty("deftu.publishing.password")
return property?.toString() ?: System.getenv("DEFTU_PUBLISHING_PASSWORD")
}

val publishingUsername = getPublishingUsername()
val publishingPassword = getPublishingPassword()
val publishingUsername = getDgtPublishingUsername()
val publishingPassword = getDgtPublishingPassword()
if (publishingUsername != null && publishingPassword != null) {
fun MavenArtifactRepository.applyCredentials() {
authentication.create<BasicAuthentication>("basic")
credentials {
username = publishingUsername
password = publishingPassword
}
}

maven {
name = RELEASES_REPO_NAME
url = uri("https://maven.deftu.dev/releases")
applyCredentials()
applyBasicCredentials(publishingUsername, publishingPassword)
}

maven {
name = SNAPSHOT_REPO_NAME
url = uri("https://maven.deftu.dev/snapshots")
applyCredentials()
applyBasicCredentials(publishingUsername, publishingPassword)
}

maven {
name = INTERNAL_REPO_NAME
url = uri("https://maven.deftu.dev/internal")
applyBasicCredentials(publishingUsername, publishingPassword)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package dev.deftu.gradle.tools.minecraft
import net.fabricmc.loom.api.LoomGradleExtensionAPI
import org.gradle.api.Project
import org.gradle.jvm.tasks.Jar
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.withType
import dev.deftu.gradle.GameInfo
import dev.deftu.gradle.MCData
import dev.deftu.gradle.utils.GameSide
import dev.deftu.gradle.utils.withLoom
import org.gradle.api.provider.Property
import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.utils.property
import java.util.*

abstract class LoomHelperExtension(
Expand All @@ -19,6 +18,12 @@ abstract class LoomHelperExtension(
internal var usingKotlinForForge = false
private set

abstract val appleSiliconFix: Property<Boolean>

init {
appleSiliconFix.convention(true)
}

/**
* Sets a Mixin config for
* Forge to use.
Expand Down Expand Up @@ -132,6 +137,10 @@ abstract class LoomHelperExtension(
if (mcData.present) {
val version = GameInfo.fetchKotlinForForgeVersion(mcData.version)

project.repositories {
maven("https://thedarkcolour.github.io/KotlinForForge/")
}

project.dependencies {
val finalNotation = if (notation.endsWith(':')) notation else "$notation:"
add("implementation", "$finalNotation$version")
Expand Down
27 changes: 26 additions & 1 deletion src/main/kotlin/dev/deftu/gradle/tools/minecraft/loom.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ plugins {
}

val mcData = MCData.from(project)
extensions.create("toolkitLoomHelper", LoomHelperExtension::class)
val extension = extensions.create("toolkitLoomHelper", LoomHelperExtension::class)
extra.set("loom.platform", if (mcData.isFabric) "fabric" else "forge")

loom {
Expand Down Expand Up @@ -74,3 +74,28 @@ if (mcData.isModLauncher) {
ignoreGradleMetadataRedirection()
}
}

afterEvaluate {
if (extension.appleSiliconFix.get()) {
if (
System.getProperty("os.arch") == "aarch64" &&
System.getProperty("os.name") == "Mac OS X"
) {
val lwjglVersion = if (mcData.version >= 1_19_00) "3.3.1" else "3.3.0"
val lwjglNatives = "natives-macos-arm64"
logger.error("Apple Silicon for Minecraft ${mcData.versionStr} ($lwjglVersion, $lwjglNatives)")

configurations.all {
resolutionStrategy {
force("org.lwjgl:lwjgl:$lwjglVersion")
force("org.lwjgl:lwjgl-openal:$lwjglVersion")
force("org.lwjgl:lwjgl-opengl:$lwjglVersion")
force("org.lwjgl:lwjgl-jemalloc:$lwjglVersion")
force("org.lwjgl:lwjgl-glfw:$lwjglVersion")
force("org.lwjgl:lwjgl-stb:$lwjglVersion")
force("org.lwjgl:lwjgl-tinyfd:$lwjglVersion")
}
}
}
}
}
23 changes: 22 additions & 1 deletion src/main/kotlin/dev/deftu/gradle/utils/configurations.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package dev.deftu.gradle.utils

import dev.deftu.gradle.MCData
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration

val Project.shadeOptionally: org.gradle.api.artifacts.Configuration
val Project.shadeOptionally: Configuration
get() = try {
configurations.getByName("shadeOptional")
} catch (e: Throwable) {
Expand All @@ -13,3 +15,22 @@ val Project.shadeOptionally: org.gradle.api.artifacts.Configuration

configuration
}

val Project.includeOrShade: Configuration
get() = try {
configurations.getByName("includeOrShade")
} catch (e: Throwable) {
if (
pluginManager.hasPlugin("dev.deftu.gradle.tools.minecraft.loom") &&
pluginManager.hasPlugin("dev.deftu.gradle.tools.shadow")
) {
val mcData = MCData.from(project)
val configuration = configurations.create("includeOrShade")
val childConfigName = if (mcData.isFabric) "include" else "shade"
val childConfig = configurations.findByName(childConfigName)
?: throw IllegalStateException("Configuration '$childConfigName' not found!")
childConfig.extendsFrom(configuration)

configuration
} else throw IllegalStateException("${project.name} does not have the required plugins to use includeOrShade (dev.deftu.gradle.tools.minecraft.loom, dev.deftu.gradle.tools.shadow)")
}
27 changes: 27 additions & 0 deletions src/main/kotlin/dev/deftu/gradle/utils/dependencies.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package dev.deftu.gradle.utils

import org.gradle.api.Project
import org.gradle.api.artifacts.repositories.MavenArtifactRepository
import org.gradle.authentication.http.BasicAuthentication
import org.gradle.kotlin.dsl.create

fun Project.getDgtPublishingUsername(): String? {
val property = project.findProperty("deftu.publishing.username")
return property?.toString() ?: System.getenv("DEFTU_PUBLISHING_USERNAME")
}

fun Project.getDgtPublishingPassword(): String? {
val property = project.findProperty("deftu.publishing.password")
return property?.toString() ?: System.getenv("DEFTU_PUBLISHING_PASSWORD")
}

fun MavenArtifactRepository.applyBasicCredentials(
username: String,
password: String
) {
authentication.create<BasicAuthentication>("basic")
credentials {
this.username = username
this.password = password
}
}
10 changes: 10 additions & 0 deletions src/main/kotlin/dev/deftu/gradle/utils/jar.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package dev.deftu.gradle.utils

import net.fabricmc.loom.task.RemapJarTask
import org.gradle.jvm.tasks.Jar

fun Jar.fromRemapJar() {
val remapJar: RemapJarTask = project.tasks.findByName("remapJar") as? RemapJarTask ?: return
dependsOn(remapJar)
from(project.zipTree(remapJar.archiveFile.get()))
}

0 comments on commit 9e636eb

Please sign in to comment.