Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions build-src/src/main/kotlin/moulconfig.base.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.gradle.external.javadoc.StandardJavadocDocletOptions
import java.nio.charset.StandardCharsets
import java.util.zip.ZipFile

repositories {
mavenLocal()
Expand All @@ -17,9 +19,64 @@ tasks.withType(JavaCompile::class) {
options.encoding = StandardCharsets.UTF_8.name()
}

// TODO: fix warnings instead of suppressing them
tasks.withType(Javadoc::class).configureEach {
(options as StandardJavadocDocletOptions).addBooleanOption("Xdoclint:all,-missing", true)
}

tasks.withType(ShadowJar::class).configureEach {
relocate("juuxel.libninepatch", "io.github.notenoughupdates.moulconfig.deps.libninepatch")
}

val checkJarForKotlinRuntime by tasks.registering {
group = "verification"
description = "Fails if built jars contain Kotlin runtime classes or Kotlin class references."
val jarTasks = tasks.withType(Jar::class)
dependsOn(jarTasks)
doLast {
fun ByteArray.containsBytes(needle: ByteArray): Boolean {
if (needle.isEmpty() || needle.size > size) return false
for (i in 0..(size - needle.size)) {
var matches = true
for (j in needle.indices) {
if (this[i + j] != needle[j]) {
matches = false
break
}
}
if (matches) return true
}
return false
}
jarTasks.forEach { jarTask ->
val jar = jarTask.archiveFile.get().asFile
if (!jar.exists() || jarTask.archiveClassifier.orNull == "sources") return@forEach
ZipFile(jar).use { zip ->
val badEntries = zip.entries().asSequence()
.map { it.name }
.filter { it.startsWith("kotlin/") || it.startsWith("kotlinx/") || it.endsWith(".kotlin_module") }
.toList()
if (badEntries.isNotEmpty()) {
error("Kotlin runtime content found in ${jar.name}: ${badEntries.take(10)}")
}
val badClass = zip.entries().asSequence()
.filter { !it.isDirectory && it.name.endsWith(".class") }
.firstOrNull { entry ->
val bytes = zip.getInputStream(entry).readBytes()
bytes.containsBytes("kotlin/".toByteArray()) || bytes.containsBytes("kotlin.".toByteArray()) ||
bytes.containsBytes("kotlinx/".toByteArray()) || bytes.containsBytes("kotlinx.".toByteArray())
}
if (badClass != null) {
error("Kotlin class reference found in ${jar.name}: ${badClass.name}")
}
}
}
}
}

tasks.matching { it.name == "check" }.configureEach {
dependsOn(checkJarForKotlinRuntime)
}
afterEvaluate {
extensions.findByType<PublishingExtension>()?.apply {
repositories {
Expand Down
8 changes: 6 additions & 2 deletions build-src/src/main/kotlin/moulconfig.fabric.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import xyz.wagyourtail.unimined.api.minecraft.task.RemapJarTask

plugins {
id("xyz.wagyourtail.unimined")
id("moulconfig.kotlin")
id("moulconfig.leaf")
id("moulconfig.manifold")
}
Expand Down Expand Up @@ -132,6 +131,11 @@ sourceSets.main {
}
}

tasks.named<Javadoc>("javadoc") {
dependsOn(tasks.compileJava)
setSource(preProcessorArgs.preprocessedSources)
}

tasks.withType(Jar::class) {
this.filesMatching(listOf("fabric.mod.json")) {
filter {
Expand Down Expand Up @@ -179,4 +183,4 @@ modernProj.configure<DokkaExtension> {
}
}
}
}
}
13 changes: 6 additions & 7 deletions build-src/src/main/kotlin/moulconfig.leaf.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import xyz.wagyourtail.unimined.util.sourceSets

plugins {
java
`maven-publish`
idea
id("moulconfig.base")
Expand All @@ -11,13 +10,16 @@ plugins {
}

val shadowInclude by configurations.creating
pluginManager.apply("java")
dependencies {
"implementation"(project(":common"))
shadowInclude(project(":common", configuration = "singleFile"))
"implementation"(Dependencies.LIB_NINE_PATCH)
shadowInclude(Dependencies.LIB_NINE_PATCH)
compileOnly(Dependencies.JB_ANNOTATIONS)
compileOnly(Dependencies.JSPECIFY)
"annotationProcessor"(Dependencies.LOMBOK)
compileOnly(Dependencies.LOMBOK)
}

val shadowJar by tasks.named("shadowJar", ShadowJar::class) {
Expand All @@ -29,13 +31,10 @@ val processResources = tasks.named("processResources", Copy::class) {
}

val sourcesJar by tasks.creating(Jar::class) {
from(sourceSets.named("main").map { it.allSource })
from(project(":common").the<SourceSetContainer>().getByName("main").allSource)
from(file("src/main/java"))
from(project(":common").file("src/main/java"))
archiveClassifier.set("sources")
}
tasks.withType<KotlinCompile> {
compilerOptions.freeCompilerArgs.add("-Xmetadata-version=2.0.0")
}
configure<PublishingExtension> {
publications {
defaultMaven {
Expand Down
3 changes: 0 additions & 3 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
plugins {
java
id("moulconfig.kotlin")
id("moulconfig.dokka.base")
`maven-publish`
id("moulconfig.base")
Expand Down Expand Up @@ -51,5 +50,3 @@ dokka {
}
}
}


Loading