Skip to content

Commit

Permalink
Merge pull request #1 from TheOnlyTails/master
Browse files Browse the repository at this point in the history
fixed some problems with publishing
  • Loading branch information
TheOnlyTails committed Mar 28, 2021
2 parents 8cbf5b2 + 1cf7c8c commit d6e798d
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 86 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,5 @@ run/

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

/logs
171 changes: 90 additions & 81 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,130 +3,140 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

// BuildScript
buildscript {
repositories {
maven(url = "https://files.minecraftforge.net/maven")
jcenter()
mavenCentral()
}

dependencies {
classpath(group = "net.minecraftforge.gradle", name = "ForgeGradle", version = "4.1.+")
classpath(group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version = "1.4.31")
}
repositories {
maven(url = "https://files.minecraftforge.net/maven")
jcenter()
mavenCentral()
}

dependencies {
classpath(group = "net.minecraftforge.gradle", name = "ForgeGradle", version = "4.1.+")
classpath(group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version = "1.4.31")
}
}

// Config -> Minecraft
val forgeVersion: String by extra
val minecraftVersion: String by extra
val kffVersion: String by extra

// Config -> Mod
val modId: String by extra
val modVersion: String by extra
val modGroup: String by extra
val author: String by extra

// Config -> Run Config
val level: String by extra
val markers: String by extra

// Config -> Gradle/Maven
val archivesBaseName: String by extra
val `package`: String by extra
val artifact: String by extra
val modVersion: String by extra
val author: String by extra

// Plugins
plugins {
`java-library`
kotlin("jvm") version ("1.4.31")
`java-library`
`maven-publish`
kotlin("jvm") version ("1.4.31")
}

apply(plugin = "net.minecraftforge.gradle")

// JVM Info
println(
"Java: ${System.getProperty("java.version")}" +
" JVM: ${System.getProperty("java.vm.version")}(${System.getProperty("java.vendor")})" +
" Arch: ${System.getProperty("os.arch")}"
"Java: ${System.getProperty("java.version")}" +
" JVM: ${System.getProperty("java.vm.version")}(${System.getProperty("java.vendor")})" +
" Arch: ${System.getProperty("os.arch")}"
)

// Minecraft Dependency
// Note: Due to the way kotlin gradle works we need to define the minecraft dependency before we configure Minecraft
dependencies {
"minecraft"(group = "net.minecraftforge", name = "forge", version = "$minecraftVersion-$forgeVersion")
"minecraft"(group = "net.minecraftforge", name = "forge", version = "$minecraftVersion-$forgeVersion")

implementation(group = "thedarkcolour", name = "kotlinforforge", version = kffVersion)
testImplementation(group = "io.kotest", name="kotest-runner-junit5", version = "4.4.3")
implementation(group = "thedarkcolour", name = "kotlinforforge", version = kffVersion)
testImplementation(group = "io.kotest", name = "kotest-runner-junit5", version = "4.4.3")
}

// Minecraft
minecraft {
mappingChannel = "official"
mappingVersion = minecraftVersion

accessTransformer(file("src/main/resources/META-INF/accesstransformer.cfg"))

runs {
config("client")

config("server")

config("data") {
args(
"--mod",
modId,
"--all",
"--output",
file("src/generated/resources/"),
"--existing",
file("src/main/resources/")
)
}
}
mappingChannel = "official"
mappingVersion = minecraftVersion

accessTransformer(file("src/main/resources/META-INF/accesstransformer.cfg"))

runs {
config("client")

config("server")

config("data") {
args(
"--mod",
artifact,
"--all",
"--output",
file("src/generated/resources/"),
"--existing",
file("src/main/resources/")
)
}
}
}

repositories {
maven {
name = "kotlinforforge"
url = uri("https://thedarkcolour.github.io/KotlinForForge/")
}
maven {
name = "kotlinforforge"
url = uri("https://thedarkcolour.github.io/KotlinForForge/")
}
}

// Setup
project.group = modGroup
project.group = `package`
project.version = "$minecraftVersion-$modVersion"
base.archivesBaseName = archivesBaseName
base.archivesBaseName = artifact

// Java 8 Target
tasks.withType<JavaCompile> {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
}

tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.useIR = true
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.useIR = true
}

// Finalize the jar by Reobf
tasks.named<Jar>("jar") { finalizedBy("reobfJar") }

// Manifest
tasks.withType<Jar> {
manifest {
attributes(
"Specification-Title" to modId,
"Specification-Vendor" to author,
"Specification-Version" to "1",
"Implementation-Title" to project.name,
"Implementation-Version" to project.version,
"Implementation-Vendor" to author,
"Implementation-Timestamp" to Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
"FMLModType" to "LIBRARY"
)
}
manifest {
attributes(
"Specification-Title" to artifact,
"Specification-Vendor" to author,
"Specification-Version" to "1",
"Implementation-Title" to project.name,
"Implementation-Version" to project.version,
"Implementation-Vendor" to author,
"Implementation-Timestamp" to Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
"FMLModType" to "LIBRARY"
)
}
}

// Utilities
// Publishing to maven central
publishing {
publications {
create<MavenPublication>("lootTables") {
groupId = `package`
artifactId = artifact
version = modVersion

from(components["java"])
}
}
}

// Utilities
typealias Date = java.util.Date
typealias SimpleDateFormat = java.text.SimpleDateFormat

Expand All @@ -138,24 +148,23 @@ typealias UserDevExtension = net.minecraftforge.gradle.userdev.UserDevExtension
typealias RunConfiguration = RunConfig.() -> Unit

fun minecraft(configuration: UserDevExtension.() -> Unit) =
configuration(extensions.getByName("minecraft") as UserDevExtension)
configuration(extensions.getByName("minecraft") as UserDevExtension)

fun NamedDomainObjectContainerScope<RunConfig>.config(name: String, additionalConfiguration: RunConfiguration = {}) {
val runDirectory = project.file("run")
val sourceSet = the<JavaPluginConvention>().sourceSets["main"]
val runDirectory = project.file("run")
val sourceSet = the<JavaPluginConvention>().sourceSets["main"]

create(name) {
workingDirectory(runDirectory)
property("forge.logging.markers", markers)
property("forge.logging.console.level", level)
create(name) {
workingDirectory(runDirectory)
property("forge.logging.markers", markers)
property("forge.logging.console.level", level)

additionalConfiguration(this)
additionalConfiguration(this)

mods { create(modId) { source(sourceSet) } }
}
mods { create(artifact) { source(sourceSet) } }
}
}


// Testing
tasks.withType<Test> {
useJUnitPlatform()
Expand Down
8 changes: 3 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ org.gradle.daemon=false
# Stuff for build.gradle.kts
# Versions
minecraftVersion=1.16.5
modVersion=0.1.0
forgeVersion=36.1.2
kffVersion=1.10.0
# https://maven.apache.org/guides/mini/guide-naming-conventions.html
modGroup=com.theonlytails.loottables
# File name for jar + '-' + version
archivesBaseName=loottables
package=com.theonlytails
artifact=loottables
modVersion=0.1.0
# Misc
modId=loottables
author=TheOnlyTails
# Config
level=debug
Expand Down
28 changes: 28 additions & 0 deletions src/test/kotlin/LootTablesTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import com.theonlytails.loottables.*
import io.kotest.core.spec.style.StringSpec
import net.minecraft.block.Blocks
import net.minecraft.block.SlabBlock
import net.minecraft.loot.LootParameterSets.BLOCK
import net.minecraft.state.properties.SlabType

class LootTablesTest : StringSpec({
"drop slabs" {
lootTable(BLOCK) {
pool {
itemEntry(Blocks.ACACIA_SLAB)

condition { survivesExplosion() }
function {
setCount(constantRange(2)) {
condition {
blockStateProperty(Blocks.ACACIA_SLAB).setProperties(
stateProperties { hasProperty(SlabBlock.TYPE, SlabType.DOUBLE) }
)
}
}
}
}
}
}
}
)

0 comments on commit d6e798d

Please sign in to comment.