mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2025-01-23 03:17:53 +01:00
I do declare
- Move source set bundling/common source set sharing logic into transitiveSourceSets and make it more flexible - Remove commonProject field from platform extension
This commit is contained in:
parent
811b0f2532
commit
045b065166
7 changed files with 170 additions and 159 deletions
|
@ -1,25 +1,18 @@
|
|||
package dev.engine_room.gradle.platform
|
||||
|
||||
import dev.engine_room.gradle.jarset.JarTaskSet
|
||||
import net.fabricmc.loom.api.LoomGradleExtensionAPI
|
||||
import net.fabricmc.loom.task.RemapJarTask
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.tasks.SourceSet
|
||||
import org.gradle.api.tasks.SourceSetContainer
|
||||
import org.gradle.api.tasks.compile.JavaCompile
|
||||
import org.gradle.api.tasks.javadoc.Javadoc
|
||||
import org.gradle.jvm.tasks.Jar
|
||||
import org.gradle.kotlin.dsl.*
|
||||
import org.gradle.language.jvm.tasks.ProcessResources
|
||||
import org.gradle.kotlin.dsl.assign
|
||||
import org.gradle.kotlin.dsl.named
|
||||
import org.gradle.kotlin.dsl.register
|
||||
import org.gradle.kotlin.dsl.the
|
||||
import java.io.File
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
open class PlatformExtension(val project: Project) {
|
||||
var commonProject: Project by Delegates.notNull()
|
||||
|
||||
val commonSourceSets: SourceSetContainer by lazy { commonProject.the<SourceSetContainer>() }
|
||||
|
||||
fun setupLoomMod(vararg sourceSets: SourceSet) {
|
||||
project.the<LoomGradleExtensionAPI>().mods.maybeCreate("main").apply {
|
||||
sourceSets.forEach(::sourceSet)
|
||||
|
@ -51,52 +44,6 @@ open class PlatformExtension(val project: Project) {
|
|||
}
|
||||
}
|
||||
|
||||
fun compileWithCommonSourceSets(vararg sourceSets: SourceSet) {
|
||||
project.tasks.apply {
|
||||
withType<JavaCompile>().configureEach {
|
||||
JarTaskSet.excludeDuplicatePackageInfos(this)
|
||||
}
|
||||
|
||||
sourceSets.forEach {
|
||||
val commonSourceSet = commonSourceSets.named(it.name).get()
|
||||
|
||||
named<JavaCompile>(it.compileJavaTaskName).configure {
|
||||
source(commonSourceSet.allJava)
|
||||
}
|
||||
named<ProcessResources>(it.processResourcesTaskName).configure {
|
||||
from(commonSourceSet.resources)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun setupFatJar(vararg sourceSets: SourceSet) {
|
||||
project.tasks.apply {
|
||||
val extraSourceSets = sourceSets.filter { it.name != "main" }.toList()
|
||||
val commonSources = sourceSets.map { commonSourceSets.named(it.name).get() }
|
||||
|
||||
named<Jar>("jar").configure {
|
||||
extraSourceSets.forEach { from(it.output) }
|
||||
|
||||
JarTaskSet.excludeDuplicatePackageInfos(this)
|
||||
}
|
||||
|
||||
named<Javadoc>("javadoc").configure {
|
||||
commonSources.forEach { source(it.allJava) }
|
||||
extraSourceSets.forEach { source(it.allJava) }
|
||||
|
||||
JarTaskSet.excludeDuplicatePackageInfos(this)
|
||||
}
|
||||
|
||||
named<Jar>("sourcesJar").configure {
|
||||
commonSources.forEach { from(it.allJava) }
|
||||
extraSourceSets.forEach { from(it.allJava) }
|
||||
|
||||
JarTaskSet.excludeDuplicatePackageInfos(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun setupTestMod(sourceSet: SourceSet) {
|
||||
project.tasks.apply {
|
||||
val testModJar = register<Jar>("testModJar") {
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
package dev.engine_room.gradle.transitive
|
||||
|
||||
import dev.engine_room.gradle.jarset.JarTaskSet
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.tasks.SourceSet
|
||||
import org.gradle.api.tasks.SourceSetContainer
|
||||
import org.gradle.api.tasks.compile.JavaCompile
|
||||
import org.gradle.api.tasks.javadoc.Javadoc
|
||||
import org.gradle.jvm.tasks.Jar
|
||||
import org.gradle.kotlin.dsl.named
|
||||
import org.gradle.kotlin.dsl.the
|
||||
import org.gradle.language.jvm.tasks.ProcessResources
|
||||
|
||||
class TransitiveSourceSetConfigurator(private val parent: TransitiveSourceSetsExtension, private val sourceSet: SourceSet) {
|
||||
|
@ -22,14 +28,21 @@ class TransitiveSourceSetConfigurator(private val parent: TransitiveSourceSetsEx
|
|||
rootRuntime()
|
||||
}
|
||||
|
||||
fun compile(vararg sourceSets: SourceSet) {
|
||||
fun compileClasspath(vararg sourceSets: SourceSet) {
|
||||
compileSourceSets += sourceSets
|
||||
for (sourceSet in sourceSets) {
|
||||
this.sourceSet.compileClasspath += sourceSet.output
|
||||
}
|
||||
}
|
||||
|
||||
fun runtime(vararg sourceSets: SourceSet) {
|
||||
fun compileClasspath(project: Project, vararg sourceSets: String) {
|
||||
val externalSourceSets = project.the<SourceSetContainer>()
|
||||
for (name in sourceSets) {
|
||||
this.sourceSet.compileClasspath += externalSourceSets.getByName(name).output
|
||||
}
|
||||
}
|
||||
|
||||
fun runtimeClasspath(vararg sourceSets: SourceSet) {
|
||||
runtimeSourceSets += sourceSets
|
||||
for (sourceSet in sourceSets) {
|
||||
this.sourceSet.runtimeClasspath += sourceSet.output
|
||||
|
@ -37,8 +50,77 @@ class TransitiveSourceSetConfigurator(private val parent: TransitiveSourceSetsEx
|
|||
}
|
||||
|
||||
fun implementation(vararg sourceSets: SourceSet) {
|
||||
compile(*sourceSets)
|
||||
runtime(*sourceSets)
|
||||
compileClasspath(*sourceSets)
|
||||
runtimeClasspath(*sourceSets)
|
||||
}
|
||||
|
||||
fun from(otherProject: Project) {
|
||||
from(otherProject, sourceSet.name)
|
||||
}
|
||||
|
||||
fun from(otherProject: Project, vararg names: String) {
|
||||
|
||||
val otherSourceSets = otherProject.the<SourceSetContainer>()
|
||||
|
||||
from(*names.map { otherSourceSets.getByName(it) }.toTypedArray())
|
||||
}
|
||||
|
||||
fun from(vararg sourceSets: SourceSet) {
|
||||
parent.project.tasks.apply {
|
||||
named<JavaCompile>(sourceSet.compileJavaTaskName).configure {
|
||||
sourceSets.forEach { source(it.allJava) }
|
||||
|
||||
JarTaskSet.excludeDuplicatePackageInfos(this)
|
||||
}
|
||||
named<ProcessResources>(sourceSet.processResourcesTaskName).configure {
|
||||
sourceSets.forEach { from(it.resources) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun bundleFrom(otherProject: Project) {
|
||||
bundleFrom(otherProject, sourceSet.name)
|
||||
}
|
||||
|
||||
fun bundleFrom(otherProject: Project, vararg names: String) {
|
||||
val otherSourceSets = otherProject.the<SourceSetContainer>()
|
||||
|
||||
bundleFrom(*names.map { otherSourceSets.getByName(it) }.toTypedArray())
|
||||
}
|
||||
|
||||
fun bundleFrom(vararg sourceSets: SourceSet) {
|
||||
from(*sourceSets)
|
||||
// The external sourceSets will be included in the jar by default since we bring it into the java compile task,
|
||||
// however we need to make sure that the javadoc and sources jars also include the external sourceSets
|
||||
bundleJavadocAndSources(*sourceSets)
|
||||
}
|
||||
|
||||
fun bundleOutput(vararg sourceSets: SourceSet) {
|
||||
bundleJavadocAndSources(*sourceSets)
|
||||
|
||||
parent.project.tasks.apply {
|
||||
named<Jar>(sourceSet.jarTaskName).configure {
|
||||
sourceSets.forEach { from(it.output) }
|
||||
|
||||
JarTaskSet.excludeDuplicatePackageInfos(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun bundleJavadocAndSources(vararg sourceSets: SourceSet) {
|
||||
parent.project.tasks.apply {
|
||||
named<Javadoc>(sourceSet.javadocTaskName).configure {
|
||||
sourceSets.forEach { source(it.allJava) }
|
||||
|
||||
JarTaskSet.excludeDuplicatePackageInfos(this)
|
||||
}
|
||||
|
||||
named<Jar>(sourceSet.sourcesJarTaskName).configure {
|
||||
sourceSets.forEach { from(it.allJava) }
|
||||
|
||||
JarTaskSet.excludeDuplicatePackageInfos(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun outgoing() {
|
||||
|
|
|
@ -24,12 +24,12 @@ transitiveSourceSets {
|
|||
}
|
||||
sourceSet(lib) {
|
||||
rootCompile()
|
||||
compile(api)
|
||||
compileClasspath(api)
|
||||
outgoing()
|
||||
}
|
||||
sourceSet(backend) {
|
||||
rootCompile()
|
||||
compile(api, lib)
|
||||
compileClasspath(api, lib)
|
||||
outgoing()
|
||||
}
|
||||
sourceSet(stubs) {
|
||||
|
@ -37,7 +37,7 @@ transitiveSourceSets {
|
|||
outgoingClasses()
|
||||
}
|
||||
sourceSet(main) {
|
||||
compile(api, lib, backend, stubs)
|
||||
compileClasspath(api, lib, backend, stubs)
|
||||
outgoing()
|
||||
}
|
||||
sourceSet(sourceSets.getByName("test")) {
|
||||
|
@ -45,7 +45,7 @@ transitiveSourceSets {
|
|||
}
|
||||
sourceSet(vanillin) {
|
||||
rootCompile()
|
||||
compile(api, lib)
|
||||
compileClasspath(api, lib)
|
||||
outgoing()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,9 @@ plugins {
|
|||
id("flywheel.platform")
|
||||
}
|
||||
|
||||
val common = ":common"
|
||||
val commonProject = project(common)
|
||||
|
||||
subproject.init("flywheel-fabric", "flywheel_group", "flywheel_version")
|
||||
|
||||
val api = sourceSets.create("api")
|
||||
|
@ -21,22 +24,34 @@ transitiveSourceSets {
|
|||
|
||||
sourceSet(api) {
|
||||
rootCompile()
|
||||
|
||||
from(commonProject)
|
||||
}
|
||||
sourceSet(lib) {
|
||||
rootCompile()
|
||||
compile(api)
|
||||
compileClasspath(api)
|
||||
|
||||
from(commonProject)
|
||||
}
|
||||
sourceSet(backend) {
|
||||
rootCompile()
|
||||
compile(api, lib)
|
||||
compileClasspath(api, lib)
|
||||
|
||||
from(commonProject)
|
||||
}
|
||||
sourceSet(stubs) {
|
||||
rootCompile()
|
||||
|
||||
from(commonProject)
|
||||
}
|
||||
sourceSet(main) {
|
||||
// Don't want stubs at runtime
|
||||
compile(stubs)
|
||||
compileClasspath(stubs)
|
||||
implementation(api, lib, backend)
|
||||
|
||||
bundleFrom(commonProject)
|
||||
|
||||
bundleOutput(api, lib, backend)
|
||||
}
|
||||
sourceSet(testMod) {
|
||||
rootCompile()
|
||||
|
@ -46,11 +61,8 @@ transitiveSourceSets {
|
|||
}
|
||||
|
||||
platform {
|
||||
commonProject = project(":common")
|
||||
compileWithCommonSourceSets(api, lib, backend, stubs, main)
|
||||
setupLoomMod(api, lib, backend, main)
|
||||
setupLoomRuns()
|
||||
setupFatJar(api, lib, backend, main)
|
||||
setupTestMod(testMod)
|
||||
}
|
||||
|
||||
|
@ -88,13 +100,13 @@ dependencies {
|
|||
|
||||
modCompileOnly("maven.modrinth:sodium:${property("sodium_version")}")
|
||||
|
||||
"forApi"(project(path = ":common", configuration = "apiClasses"))
|
||||
"forLib"(project(path = ":common", configuration = "libClasses"))
|
||||
"forBackend"(project(path = ":common", configuration = "backendClasses"))
|
||||
"forStubs"(project(path = ":common", configuration = "stubsClasses"))
|
||||
"forMain"(project(path = ":common", configuration = "mainClasses"))
|
||||
"forApi"(project(path = common, configuration = "apiClasses"))
|
||||
"forLib"(project(path = common, configuration = "libClasses"))
|
||||
"forBackend"(project(path = common, configuration = "backendClasses"))
|
||||
"forStubs"(project(path = common, configuration = "stubsClasses"))
|
||||
"forMain"(project(path = common, configuration = "mainClasses"))
|
||||
|
||||
"forLib"(project(path = ":common", configuration = "libResources"))
|
||||
"forBackend"(project(path = ":common", configuration = "backendResources"))
|
||||
"forMain"(project(path = ":common", configuration = "mainResources"))
|
||||
"forLib"(project(path = common, configuration = "libResources"))
|
||||
"forBackend"(project(path = common, configuration = "backendResources"))
|
||||
"forMain"(project(path = common, configuration = "mainResources"))
|
||||
}
|
||||
|
|
|
@ -7,6 +7,9 @@ plugins {
|
|||
id("flywheel.platform")
|
||||
}
|
||||
|
||||
val common = ":common"
|
||||
val commonProject = project(common)
|
||||
|
||||
subproject.init("flywheel-forge", "flywheel_group", "flywheel_version")
|
||||
|
||||
val api = sourceSets.create("api")
|
||||
|
@ -21,20 +24,32 @@ transitiveSourceSets {
|
|||
|
||||
sourceSet(api) {
|
||||
rootCompile()
|
||||
|
||||
from(commonProject)
|
||||
}
|
||||
sourceSet(lib) {
|
||||
rootCompile()
|
||||
compile(api)
|
||||
compileClasspath(api)
|
||||
|
||||
from(commonProject)
|
||||
}
|
||||
sourceSet(backend) {
|
||||
rootCompile()
|
||||
compile(api, lib)
|
||||
compileClasspath(api, lib)
|
||||
|
||||
from(commonProject)
|
||||
}
|
||||
sourceSet(stubs) {
|
||||
rootCompile()
|
||||
|
||||
from(commonProject)
|
||||
}
|
||||
sourceSet(main) {
|
||||
compile(api, lib, backend, stubs)
|
||||
compileClasspath(api, lib, backend, stubs)
|
||||
|
||||
bundleFrom(commonProject)
|
||||
|
||||
bundleOutput(api, lib, backend)
|
||||
}
|
||||
sourceSet(testMod) {
|
||||
rootCompile()
|
||||
|
@ -44,11 +59,8 @@ transitiveSourceSets {
|
|||
}
|
||||
|
||||
platform {
|
||||
commonProject = project(":common")
|
||||
compileWithCommonSourceSets(api, lib, backend, stubs, main)
|
||||
setupLoomMod(api, lib, backend, main)
|
||||
setupLoomRuns()
|
||||
setupFatJar(api, lib, backend, main)
|
||||
setupTestMod(testMod)
|
||||
}
|
||||
|
||||
|
@ -97,13 +109,13 @@ dependencies {
|
|||
|
||||
modCompileOnly("maven.modrinth:embeddium:${property("embeddium_version")}")
|
||||
|
||||
"forApi"(project(path = ":common", configuration = "apiClasses"))
|
||||
"forLib"(project(path = ":common", configuration = "libClasses"))
|
||||
"forBackend"(project(path = ":common", configuration = "backendClasses"))
|
||||
"forStubs"(project(path = ":common", configuration = "stubsClasses"))
|
||||
"forMain"(project(path = ":common", configuration = "mainClasses"))
|
||||
"forApi"(project(path = common, configuration = "apiClasses"))
|
||||
"forLib"(project(path = common, configuration = "libClasses"))
|
||||
"forBackend"(project(path = common, configuration = "backendClasses"))
|
||||
"forStubs"(project(path = common, configuration = "stubsClasses"))
|
||||
"forMain"(project(path = common, configuration = "mainClasses"))
|
||||
|
||||
"forLib"(project(path = ":common", configuration = "libResources"))
|
||||
"forBackend"(project(path = ":common", configuration = "backendResources"))
|
||||
"forMain"(project(path = ":common", configuration = "mainResources"))
|
||||
"forLib"(project(path = common, configuration = "libResources"))
|
||||
"forBackend"(project(path = common, configuration = "backendResources"))
|
||||
"forMain"(project(path = common, configuration = "mainResources"))
|
||||
}
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
import dev.engine_room.gradle.jarset.JarTaskSet
|
||||
import org.gradle.jvm.tasks.Jar
|
||||
|
||||
plugins {
|
||||
idea
|
||||
java
|
||||
|
@ -10,41 +7,23 @@ plugins {
|
|||
id("flywheel.platform")
|
||||
}
|
||||
|
||||
val common = ":common"
|
||||
val platform = ":fabric"
|
||||
|
||||
subproject.init("vanillin-fabric", "vanillin_group", "vanillin_version")
|
||||
|
||||
val main = sourceSets.getByName("main")
|
||||
|
||||
platform {
|
||||
commonProject = project(":common")
|
||||
setupLoomRuns()
|
||||
}
|
||||
|
||||
listOf("api", "lib")
|
||||
.map { project(":fabric").sourceSets.named(it).get() }
|
||||
.forEach { main.compileClasspath += it.output }
|
||||
transitiveSourceSets {
|
||||
sourceSet(main) {
|
||||
compileClasspath(project(platform), "api", "lib")
|
||||
|
||||
val commonSourceSet = platform.commonSourceSets.named("vanillin").get()
|
||||
|
||||
tasks.named<Javadoc>("javadoc").configure {
|
||||
source(commonSourceSet.allJava)
|
||||
|
||||
JarTaskSet.excludeDuplicatePackageInfos(this)
|
||||
}
|
||||
|
||||
tasks.named<Jar>("sourcesJar").configure {
|
||||
from(commonSourceSet.allJava)
|
||||
|
||||
JarTaskSet.excludeDuplicatePackageInfos(this)
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
JarTaskSet.excludeDuplicatePackageInfos(this)
|
||||
}
|
||||
tasks.named<JavaCompile>(main.compileJavaTaskName).configure {
|
||||
source(commonSourceSet.allJava)
|
||||
}
|
||||
tasks.named<ProcessResources>(main.processResourcesTaskName).configure {
|
||||
from(commonSourceSet.resources)
|
||||
bundleFrom(project(common), "vanillin")
|
||||
}
|
||||
}
|
||||
|
||||
jarSets {
|
||||
|
@ -68,10 +47,10 @@ dependencies {
|
|||
|
||||
modCompileOnly("maven.modrinth:sodium:${property("sodium_version")}")
|
||||
|
||||
compileOnly(project(path = ":common", configuration = "vanillinClasses"))
|
||||
compileOnly(project(path = ":common", configuration = "vanillinResources"))
|
||||
compileOnly(project(path = common, configuration = "vanillinClasses"))
|
||||
compileOnly(project(path = common, configuration = "vanillinResources"))
|
||||
|
||||
// JiJ flywheel proper
|
||||
include(project(path = ":fabric", configuration = "flywheelRemap"))
|
||||
runtimeOnly(project(path = ":fabric", configuration = "flywheelDev"))
|
||||
include(project(path = platform, configuration = "flywheelRemap"))
|
||||
runtimeOnly(project(path = platform, configuration = "flywheelDev"))
|
||||
}
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
import dev.engine_room.gradle.jarset.JarTaskSet
|
||||
import org.gradle.jvm.tasks.Jar
|
||||
|
||||
plugins {
|
||||
idea
|
||||
java
|
||||
|
@ -10,41 +7,23 @@ plugins {
|
|||
id("flywheel.platform")
|
||||
}
|
||||
|
||||
val common = ":common"
|
||||
val platform = ":forge"
|
||||
|
||||
subproject.init("vanillin-forge", "vanillin_group", "vanillin_version")
|
||||
|
||||
val main = sourceSets.getByName("main")
|
||||
|
||||
platform {
|
||||
commonProject = project(":common")
|
||||
setupLoomRuns()
|
||||
}
|
||||
|
||||
listOf("api", "lib")
|
||||
.map { project(":forge").sourceSets.named(it).get() }
|
||||
.forEach { main.compileClasspath += it.output }
|
||||
transitiveSourceSets {
|
||||
sourceSet(main) {
|
||||
compileClasspath(project(platform), "api", "lib")
|
||||
|
||||
val commonSourceSet = platform.commonSourceSets.named("vanillin").get()
|
||||
|
||||
tasks.named<Javadoc>("javadoc").configure {
|
||||
source(commonSourceSet.allJava)
|
||||
|
||||
JarTaskSet.excludeDuplicatePackageInfos(this)
|
||||
}
|
||||
|
||||
tasks.named<Jar>("sourcesJar").configure {
|
||||
from(commonSourceSet.allJava)
|
||||
|
||||
JarTaskSet.excludeDuplicatePackageInfos(this)
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
JarTaskSet.excludeDuplicatePackageInfos(this)
|
||||
}
|
||||
tasks.named<JavaCompile>(main.compileJavaTaskName).configure {
|
||||
source(commonSourceSet.allJava)
|
||||
}
|
||||
tasks.named<ProcessResources>(main.processResourcesTaskName).configure {
|
||||
from(commonSourceSet.resources)
|
||||
bundleFrom(project(common), "vanillin")
|
||||
}
|
||||
}
|
||||
|
||||
jarSets {
|
||||
|
@ -79,10 +58,10 @@ dependencies {
|
|||
|
||||
modCompileOnly("maven.modrinth:embeddium:${property("embeddium_version")}")
|
||||
|
||||
compileOnly(project(path = ":common", configuration = "vanillinClasses"))
|
||||
compileOnly(project(path = ":common", configuration = "vanillinResources"))
|
||||
compileOnly(project(path = common, configuration = "vanillinClasses"))
|
||||
compileOnly(project(path = common, configuration = "vanillinResources"))
|
||||
|
||||
// JiJ flywheel proper
|
||||
include(project(path = ":forge", configuration = "flywheelRemap"))
|
||||
runtimeOnly(project(path = ":forge", configuration = "flywheelDev"))
|
||||
include(project(path = platform, configuration = "flywheelRemap"))
|
||||
runtimeOnly(project(path = platform, configuration = "flywheelDev"))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue