- 
                Notifications
    You must be signed in to change notification settings 
- Fork 38
Add Kotlin DSL template #23
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
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,116 @@ | ||||||||
| plugins { | ||||||||
| id("fabric-loom") version "1.0-SNAPSHOT" | ||||||||
| id("maven-publish") | ||||||||
| <% if (it.kotlin) { %>kotlin("jvm") version "<%= it.kotlin.kotlinVersion %>"<% } %> | ||||||||
| } | ||||||||
|  | ||||||||
|         
                  KosmX marked this conversation as resolved.
              Show resolved
            Hide resolved | ||||||||
| base.archivesName.set(project.properties["archives_base_name"] as String) | ||||||||
| version = project.properties["mod_version"] as String | ||||||||
| group = project.properties["maven_group"] as String | ||||||||
|         
                  KosmX marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||||||||
|  | ||||||||
| 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("modid") { | ||||||||
|         
                  KosmX marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||||||||
| 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.properties["minecraft_version"]}") | ||||||||
| mappings("net.fabricmc:yarn:${project.properties["yarn_mappings"]}:v2") | ||||||||
| modImplementation("net.fabricmc:fabric-loader:${project.properties["loader_version"]}") | ||||||||
|  | ||||||||
| // Fabric API. This is technically optional, but you probably want it anyway. | ||||||||
| modImplementation("net.fabricmc.fabric-api:fabric-api:${project.properties["fabric_version"]}") | ||||||||
| <% if (it.kotlin) { %> modImplementation("net.fabricmc:fabric-language-kotlin:${project.properties["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.properties["fabric_version"]}") | ||||||||
|         
                  KosmX marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||||||||
| } | ||||||||
|  | ||||||||
| tasks { | ||||||||
| processResources { | ||||||||
| inputs.property("version", project.version) | ||||||||
| filteringCharset = "UTF-8" | ||||||||
|         
                  KosmX marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||||||||
|  | ||||||||
| filesMatching("fabric.mod.json") { | ||||||||
| expand(mapOf("version" to project.version)) | ||||||||
|         
                  KosmX marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||||||||
| } | ||||||||
| } | ||||||||
|  | ||||||||
| // Minecraft 1.18 (1.18-pre2) upwards uses Java 17. | ||||||||
|         
                  KosmX marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||||||||
| val targetJavaVersion = <%= it.java.release %> | ||||||||
|         
                  KosmX marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||||||||
| withType<JavaCompile> { | ||||||||
| options.encoding = "UTF-8" | ||||||||
|         
                  KosmX marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||||||||
| options.release.set(targetJavaVersion) | ||||||||
| } | ||||||||
|  | ||||||||
| <% if (it.kotlin) { %> withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> { | ||||||||
| kotlinOptions.jvmTarget = targetJavaVersion.toString() | ||||||||
| }<% } %> | ||||||||
|  | ||||||||
| 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
       
 | ||||||||
| toolchain.languageVersion.set(JavaLanguageVersion.of(JavaVersion.toVersion(targetJavaVersion).toString())) | ||||||||
|         
                  KosmX marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||||||||
|  | ||||||||
| // 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}" } | ||||||||
|          | ||||||||
| rename { "${it}_${base.archivesName}" } | |
| rename { "${it}_${base.archivesName.get()}" } | 
archivesName is a Property<String>
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.
done. but it worked without get()
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| pluginManagement { | ||
| repositories { | ||
| maven("https://maven.fabricmc.net/") { | ||
| name= "Fabric" | ||
|         
                  KosmX marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| } | ||
| mavenCentral() | ||
| gradlePluginPortal() | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.