-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Kotlin DSL template #23
base: main
Are you sure you want to change the base?
Changes from all commits
842e639
7bd0823
76bc7b0
465f280
9729a47
732d3ec
c344ab4
5072463
a9ec5fc
aacc801
66851cc
bbf513e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import type { ComputedConfiguration, TemplateWriter } from './template'; | ||
import { renderTemplate } from './eta'; | ||
|
||
import gradlePropertiesTemplate from './templates/gradle/groovy/gradle.properties.eta?raw'; | ||
import buildGradleTemplate from './templates/gradle/kotlin/build.gradle.kts.eta?raw'; | ||
import settingsGradle from './templates/gradle/kotlin/settings.gradle.kts?raw'; | ||
import { getJavaVersion } from './java'; | ||
|
||
export async function addKotlinGradle(writer: TemplateWriter, config: ComputedConfiguration) { | ||
await writer.write('gradle.properties', renderTemplate(gradlePropertiesTemplate, config)); | ||
await writer.write('build.gradle.kts', renderTemplate(buildGradleTemplate, {...config, java: getJavaVersion(config.minecraftVersion)})); | ||
await writer.write('settings.gradle.kts', settingsGradle); | ||
} |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,113 @@ | ||||||||
plugins { | ||||||||
id("fabric-loom") version "1.2-SNAPSHOT" | ||||||||
id("maven-publish")<% if (it.kotlin) { %> | ||||||||
kotlin("jvm") version "<%= it.kotlin.kotlinVersion %>"<% } %> | ||||||||
} | ||||||||
|
||||||||
KosmX marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
java.sourceCompatibility = JavaVersion.<%= it.java.compatibility %> | ||||||||
java.targetCompatibility = JavaVersion.<%= it.java.compatibility %> | ||||||||
|
||||||||
base.archivesName.set(project.property("archives_base_name") as String) | ||||||||
version = project.property("mod_version") as String | ||||||||
group = project.property("maven_group") as String | ||||||||
|
||||||||
repositories { | ||||||||
// Add repositories to retrieve artifacts from in here. | ||||||||
// You should only use this when depending on other mods because | ||||||||
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically. | ||||||||
// See https://docs.gradle.org/current/userguide/declaring_repositories.html | ||||||||
// for more information about repositories. | ||||||||
} | ||||||||
<% if (it.dataGeneration || it.splitSources) { %> | ||||||||
loom { | ||||||||
<% if (it.splitSources) { %> splitEnvironmentSourceSets() | ||||||||
|
||||||||
mods { | ||||||||
create("<%= it.modid %>") { | ||||||||
sourceSet(sourceSets["main"]) | ||||||||
sourceSet(sourceSets["client"]) | ||||||||
} | ||||||||
} | ||||||||
<% } %><% if (it.dataGeneration) { %> runs { | ||||||||
create("datagen") { | ||||||||
inherit(runConfigs["server"]) | ||||||||
name("Data Generation") | ||||||||
vmArg("-Dfabric-api.datagen") | ||||||||
vmArg("-Dfabric-api.datagen.output-dir=${file("src/main/generated")}") | ||||||||
vmArg("-Dfabric-api.datagen.modid=<%= it.modid %>") | ||||||||
|
||||||||
runDir("build/datagen") | ||||||||
} | ||||||||
}<% } %> | ||||||||
} | ||||||||
<% } %><% if (it.dataGeneration) { %> | ||||||||
sourceSets { | ||||||||
main { | ||||||||
resources { | ||||||||
srcDirs += file("src/main/generated") | ||||||||
} | ||||||||
} | ||||||||
}<% } %> | ||||||||
|
||||||||
dependencies { | ||||||||
// To change the versions see the gradle.properties file | ||||||||
minecraft("com.mojang:minecraft:${project.property("minecraft_version")}") | ||||||||
mappings("net.fabricmc:yarn:${project.property("yarn_mappings")}:v2") | ||||||||
modImplementation("net.fabricmc:fabric-loader:${project.property("loader_version")}") | ||||||||
|
||||||||
// Fabric API. This is technically optional, but you probably want it anyway. | ||||||||
modImplementation("net.fabricmc.fabric-api:fabric-api:${project.property("fabric_version")}") | ||||||||
<% if (it.kotlin) { %> modImplementation("net.fabricmc:fabric-language-kotlin:${project.property("fabric_kotlin_version")}")<% } %> | ||||||||
// Uncomment the following line to enable the deprecated Fabric API modules. | ||||||||
// These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time. | ||||||||
|
||||||||
// modImplementation("net.fabricmc.fabric-api:fabric-api-deprecated:${project.property("fabric_version")}") | ||||||||
} | ||||||||
|
||||||||
<% if (it.kotlin) { %> | ||||||||
kotlin { | ||||||||
jvmToolchain(java.targetCompatibility.majorVersion.toInt()) | ||||||||
} | ||||||||
<% } %> | ||||||||
tasks { | ||||||||
processResources { | ||||||||
inputs.property("version", project.version) | ||||||||
|
||||||||
filesMatching("fabric.mod.json") { | ||||||||
expand("version" to project.version) | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
withType<JavaCompile> { | ||||||||
options.release.set(java.targetCompatibility.majorVersion.toInt()) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't create more constants, This PR is about Kotlin DSL, but I think, it should be changed in groovy to reuse the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO the best solution would be to use top-level constants in both Kotlin and Groovy buildscripts ( Since "this PR is about Kotlin DSL", shouldn't it follow the existing pattern? |
||||||||
} | ||||||||
java { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task | ||||||||
// if it is present. | ||||||||
// If you remove this line, sources will not be generated. | ||||||||
withSourcesJar() | ||||||||
} | ||||||||
|
||||||||
jar { | ||||||||
from("LICENSE") { | ||||||||
rename { "${it}_${base.archivesName.get()}" } | ||||||||
} | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
// configure the maven publication | ||||||||
publishing { | ||||||||
publications { | ||||||||
create<MavenPublication>("mavenJava") { | ||||||||
from(components["java"]) | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. | ||||||||
repositories { | ||||||||
// Add repositories to publish to here. | ||||||||
// Notice: This block does NOT have the same function as the block in the top level. | ||||||||
// The repositories here will be used for publishing your artifact, not for | ||||||||
// retrieving dependencies. | ||||||||
} | ||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
pluginManagement { | ||
repositories { | ||
maven("https://maven.fabricmc.net/") { | ||
name = "Fabric" | ||
} | ||
mavenCentral() | ||
gradlePluginPortal() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The standard Gradle plugins have extension properties that avoid the use of
id
. See Gradle's own example:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, but I personally like
id("maven-publish")
more. There are no ` characters and more consistent.Maybe vote?