mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-11-10 12:34:11 +01:00
Declaration of jar
- Expose desired behaviors from platform plugin via an extension - Move PlatformPlugin to platform package
This commit is contained in:
parent
fb798112d7
commit
15184b8ccd
@ -22,7 +22,7 @@ gradlePlugin {
|
|||||||
plugins {
|
plugins {
|
||||||
create("platformPlugin") {
|
create("platformPlugin") {
|
||||||
id = "flywheel.platform"
|
id = "flywheel.platform"
|
||||||
implementationClass = "com.jozufozu.gradle.PlatformPlugin"
|
implementationClass = "com.jozufozu.gradle.platform.PlatformPlugin"
|
||||||
}
|
}
|
||||||
create("jarSetPlugin") {
|
create("jarSetPlugin") {
|
||||||
id = "flywheel.jar-sets"
|
id = "flywheel.jar-sets"
|
||||||
|
@ -1,115 +0,0 @@
|
|||||||
package com.jozufozu.gradle
|
|
||||||
|
|
||||||
import com.jozufozu.gradle.jarset.JarTaskSet
|
|
||||||
import net.fabricmc.loom.api.LoomGradleExtensionAPI
|
|
||||||
import net.fabricmc.loom.task.RemapJarTask
|
|
||||||
import net.fabricmc.loom.task.RemapSourcesJarTask
|
|
||||||
import org.gradle.api.Plugin
|
|
||||||
import org.gradle.api.Project
|
|
||||||
import org.gradle.api.publish.PublishingExtension
|
|
||||||
import org.gradle.api.publish.maven.MavenPublication
|
|
||||||
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.the
|
|
||||||
import org.gradle.language.jvm.tasks.ProcessResources
|
|
||||||
|
|
||||||
class PlatformPlugin: Plugin<Project> {
|
|
||||||
override fun apply(project: Project) {
|
|
||||||
val commonProject = project.project(":common")
|
|
||||||
val commonSourceSets = commonProject.the<SourceSetContainer>()
|
|
||||||
|
|
||||||
val sourceSets = project.the<SourceSetContainer>()
|
|
||||||
val loom = project.the<LoomGradleExtensionAPI>()
|
|
||||||
val publishing = project.the<PublishingExtension>()
|
|
||||||
|
|
||||||
val platformImpl = sourceSets.named("main").get()
|
|
||||||
val platformApi = sourceSets.create("api")
|
|
||||||
val platformLib = sourceSets.create("lib")
|
|
||||||
val platformBackend = sourceSets.create("backend")
|
|
||||||
|
|
||||||
// This is needed for both platforms.
|
|
||||||
val mainMod = loom.mods.maybeCreate("main")
|
|
||||||
mainMod.sourceSet(platformApi)
|
|
||||||
mainMod.sourceSet(platformLib)
|
|
||||||
mainMod.sourceSet(platformBackend)
|
|
||||||
mainMod.sourceSet(platformImpl)
|
|
||||||
|
|
||||||
val commonApi = commonSourceSets.named("api").get()
|
|
||||||
val commonLib = commonSourceSets.named("lib").get()
|
|
||||||
val commonBackend = commonSourceSets.named("backend").get()
|
|
||||||
val commonImpl = commonSourceSets.named("main").get()
|
|
||||||
|
|
||||||
val commonSources = listOf(commonApi, commonLib, commonBackend, commonImpl)
|
|
||||||
|
|
||||||
// Directly compile the platform sources with the common sources
|
|
||||||
includeFromCommon(project, platformApi, commonApi)
|
|
||||||
includeFromCommon(project, platformLib, commonLib)
|
|
||||||
includeFromCommon(project, platformBackend, commonBackend)
|
|
||||||
includeFromCommon(project, platformImpl, commonImpl)
|
|
||||||
|
|
||||||
val tasks = project.tasks
|
|
||||||
|
|
||||||
tasks.withType(JavaCompile::class.java).configureEach {
|
|
||||||
JarTaskSet.excludeDuplicatePackageInfos(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.named("jar", Jar::class.java).configure {
|
|
||||||
from(platformApi.output, platformLib.output, platformBackend.output)
|
|
||||||
|
|
||||||
JarTaskSet.excludeDuplicatePackageInfos(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.named("javadoc", Javadoc::class.java).configure {
|
|
||||||
commonSources.forEach { source(it.allJava) }
|
|
||||||
|
|
||||||
source(platformApi.allJava, platformLib.allJava, platformBackend.allJava)
|
|
||||||
|
|
||||||
JarTaskSet.excludeDuplicatePackageInfos(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.named("sourcesJar", Jar::class.java).configure {
|
|
||||||
commonSources.forEach { from(it.allJava) }
|
|
||||||
|
|
||||||
from(platformApi.allJava, platformLib.allJava, platformBackend.allJava)
|
|
||||||
|
|
||||||
JarTaskSet.excludeDuplicatePackageInfos(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
val remapJar = tasks.named("remapJar", RemapJarTask::class.java)
|
|
||||||
val remapSourcesJar = tasks.named("remapSourcesJar", RemapSourcesJarTask::class.java)
|
|
||||||
val javadocJar = tasks.named("javadocJar", Jar::class.java)
|
|
||||||
|
|
||||||
val apiSet = JarTaskSet.create(project, "api", platformApi, platformLib)
|
|
||||||
|
|
||||||
val mcVersion = project.property("artifact_minecraft_version")
|
|
||||||
|
|
||||||
publishing.publications {
|
|
||||||
// we should be using remapped on both Fabric and Forge because Forge needs to put things in srg
|
|
||||||
register("mavenApi", MavenPublication::class.java) {
|
|
||||||
artifact(apiSet.remapJar)
|
|
||||||
artifact(apiSet.remapSources)
|
|
||||||
artifact(apiSet.javadocJar)
|
|
||||||
artifactId = "flywheel-${project.name}-api-${mcVersion}"
|
|
||||||
}
|
|
||||||
register("mavenImpl", MavenPublication::class.java) {
|
|
||||||
artifact(remapJar)
|
|
||||||
artifact(remapSourcesJar)
|
|
||||||
artifact(javadocJar)
|
|
||||||
artifactId = "flywheel-${project.name}-${mcVersion}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun includeFromCommon(project: Project, sourceSet: SourceSet, commonSourceSet: SourceSet) {
|
|
||||||
project.tasks.named(sourceSet.compileJavaTaskName, JavaCompile::class.java).configure {
|
|
||||||
source(commonSourceSet.allJava)
|
|
||||||
}
|
|
||||||
|
|
||||||
project.tasks.named(sourceSet.processResourcesTaskName, ProcessResources::class.java).configure {
|
|
||||||
from(commonSourceSet.resources)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -5,7 +5,7 @@ import org.gradle.api.tasks.Delete
|
|||||||
import org.gradle.api.tasks.SourceSet
|
import org.gradle.api.tasks.SourceSet
|
||||||
|
|
||||||
open class PackageInfosExtension(private val project: Project) {
|
open class PackageInfosExtension(private val project: Project) {
|
||||||
fun forSourceSets(vararg sourceSets: SourceSet) {
|
fun sources(vararg sourceSets: SourceSet) {
|
||||||
for (sourceSet in sourceSets) {
|
for (sourceSet in sourceSets) {
|
||||||
forSourceSet(sourceSet)
|
forSourceSet(sourceSet)
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,164 @@
|
|||||||
|
package com.jozufozu.gradle.platform
|
||||||
|
|
||||||
|
import com.jozufozu.gradle.jarset.JarTaskSet
|
||||||
|
import net.fabricmc.loom.api.LoomGradleExtensionAPI
|
||||||
|
import net.fabricmc.loom.task.RemapJarTask
|
||||||
|
import net.fabricmc.loom.task.RemapSourcesJarTask
|
||||||
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.api.publish.PublishingExtension
|
||||||
|
import org.gradle.api.publish.maven.MavenPublication
|
||||||
|
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.provideDelegate
|
||||||
|
import org.gradle.kotlin.dsl.the
|
||||||
|
import org.gradle.language.jvm.tasks.ProcessResources
|
||||||
|
import kotlin.properties.ReadWriteProperty
|
||||||
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
|
open class PlatformExtension(val project: Project) {
|
||||||
|
var commonProject: Project by DependentProject(this.project)
|
||||||
|
|
||||||
|
var modArtifactId: String = "flywheel-${project.name}-${project.property("artifact_minecraft_version")}"
|
||||||
|
|
||||||
|
var apiArtifactId: String = "flywheel-${project.name}-api-${project.property("artifact_minecraft_version")}"
|
||||||
|
|
||||||
|
private val sources = mutableSetOf<SourceSet>()
|
||||||
|
private val commonSourceSets: SourceSetContainer by lazy { commonProject.the<SourceSetContainer>() }
|
||||||
|
|
||||||
|
fun sources(vararg sourceSets: SourceSet) {
|
||||||
|
this.sources.addAll(sourceSets)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setupLoomMod() {
|
||||||
|
project.the<LoomGradleExtensionAPI>().mods.maybeCreate("main").apply {
|
||||||
|
sources.forEach(::sourceSet)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setupLoomRuns() {
|
||||||
|
project.the<LoomGradleExtensionAPI>().runs.apply {
|
||||||
|
named("client") {
|
||||||
|
isIdeConfigGenerated = true
|
||||||
|
|
||||||
|
// Turn on our own debug flags
|
||||||
|
property("flw.dumpShaderSource", "true")
|
||||||
|
property("flw.debugMemorySafety", "true")
|
||||||
|
|
||||||
|
// Turn on mixin debug flags
|
||||||
|
property("mixin.debug.export", "true")
|
||||||
|
property("mixin.debug.verbose", "true")
|
||||||
|
|
||||||
|
// 720p baby!
|
||||||
|
programArgs("--width", "1280", "--height", "720")
|
||||||
|
}
|
||||||
|
|
||||||
|
// We're a client mod, but we need to make sure we correctly render when playing on a server.
|
||||||
|
named("server") {
|
||||||
|
isIdeConfigGenerated = true
|
||||||
|
programArgs("--nogui")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun compileWithCommonSourceSets() {
|
||||||
|
project.tasks.apply {
|
||||||
|
withType(JavaCompile::class.java).configureEach {
|
||||||
|
JarTaskSet.excludeDuplicatePackageInfos(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
sources.forEach {
|
||||||
|
val commonSourceSet = commonSourceSets.named(it.name).get()
|
||||||
|
|
||||||
|
named(it.compileJavaTaskName, JavaCompile::class.java).configure {
|
||||||
|
source(commonSourceSet.allJava)
|
||||||
|
}
|
||||||
|
named(it.processResourcesTaskName, ProcessResources::class.java).configure {
|
||||||
|
from(commonSourceSet.resources)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setupFatJar() {
|
||||||
|
project.tasks.apply {
|
||||||
|
val extraSourceSets = sources.filter { it.name != "main" }.toList()
|
||||||
|
val commonSources = sources.map { commonSourceSets.named(it.name).get() }
|
||||||
|
|
||||||
|
named("jar", Jar::class.java).configure {
|
||||||
|
extraSourceSets.forEach { from(it.output) }
|
||||||
|
|
||||||
|
JarTaskSet.excludeDuplicatePackageInfos(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
named("javadoc", Javadoc::class.java).configure {
|
||||||
|
commonSources.forEach { source(it.allJava) }
|
||||||
|
extraSourceSets.forEach { source(it.allJava) }
|
||||||
|
|
||||||
|
JarTaskSet.excludeDuplicatePackageInfos(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
named("sourcesJar", Jar::class.java).configure {
|
||||||
|
commonSources.forEach { from(it.allJava) }
|
||||||
|
extraSourceSets.forEach { from(it.allJava) }
|
||||||
|
|
||||||
|
JarTaskSet.excludeDuplicatePackageInfos(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun publishMod() {
|
||||||
|
val remapJar = project.tasks.named("remapJar", RemapJarTask::class.java)
|
||||||
|
val remapSourcesJar = project.tasks.named("remapSourcesJar", RemapSourcesJarTask::class.java)
|
||||||
|
val javadocJar = project.tasks.named("javadocJar", Jar::class.java)
|
||||||
|
|
||||||
|
project.the<PublishingExtension>().publications {
|
||||||
|
register("modMaven", MavenPublication::class.java) {
|
||||||
|
artifact(remapJar)
|
||||||
|
artifact(remapSourcesJar)
|
||||||
|
artifact(javadocJar)
|
||||||
|
artifactId = modArtifactId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun publishRemap(artifactId: String, jarSet: JarTaskSet) {
|
||||||
|
project.the<PublishingExtension>().publications {
|
||||||
|
register("${jarSet.name}RemapMaven", MavenPublication::class.java) {
|
||||||
|
artifact(jarSet.remapJar)
|
||||||
|
artifact(jarSet.remapSources)
|
||||||
|
artifact(jarSet.javadocJar)
|
||||||
|
this.artifactId = artifactId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun publish(artifactId: String, jarSet: JarTaskSet) {
|
||||||
|
project.the<PublishingExtension>().publications {
|
||||||
|
register("${jarSet.name}Maven", MavenPublication::class.java) {
|
||||||
|
artifact(jarSet.jar)
|
||||||
|
artifact(jarSet.sources)
|
||||||
|
artifact(jarSet.javadocJar)
|
||||||
|
this.artifactId = artifactId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class DependentProject(private val thisProject: Project) : ReadWriteProperty<Any?, Project> {
|
||||||
|
private var value: Project? = null
|
||||||
|
|
||||||
|
override fun getValue(thisRef: Any?, property: KProperty<*>): Project {
|
||||||
|
return value ?: throw IllegalStateException("Property ${property.name} should be initialized before get.")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setValue(thisRef: Any?, property: KProperty<*>, value: Project) {
|
||||||
|
this.value = value
|
||||||
|
thisProject.evaluationDependsOn(value.path)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString(): String =
|
||||||
|
"NotNullProperty(${if (value != null) "value=$value" else "value not initialized yet"})"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.jozufozu.gradle.platform
|
||||||
|
|
||||||
|
import org.gradle.api.Plugin
|
||||||
|
import org.gradle.api.Project
|
||||||
|
|
||||||
|
class PlatformPlugin: Plugin<Project> {
|
||||||
|
override fun apply(project: Project) {
|
||||||
|
project.extensions.create("platform", PlatformExtension::class.java)
|
||||||
|
}
|
||||||
|
}
|
@ -33,23 +33,15 @@ transitiveSourceSets {
|
|||||||
}
|
}
|
||||||
|
|
||||||
defaultPackageInfos {
|
defaultPackageInfos {
|
||||||
forSourceSets sourceSets.api, sourceSets.lib, sourceSets.backend, sourceSets.main
|
sources sourceSets.api, sourceSets.lib, sourceSets.backend, sourceSets.main
|
||||||
}
|
}
|
||||||
|
|
||||||
// For sharing with other subprojects.
|
// For sharing with other subprojects.
|
||||||
jarSets {
|
jarSets {
|
||||||
createJars('apiOnly', sourceSets.api).configure {
|
createJars('apiOnly', sourceSets.api).createOutgoingConfiguration('common')
|
||||||
it.createOutgoingConfiguration('common')
|
createJars('lib').createOutgoingConfiguration('common')
|
||||||
}
|
createJars('backend').createOutgoingConfiguration('common')
|
||||||
createJars('lib').configure {
|
createJars('impl', sourceSets.main).createOutgoingConfiguration('common')
|
||||||
it.createOutgoingConfiguration('common')
|
|
||||||
}
|
|
||||||
createJars('backend').configure {
|
|
||||||
it.createOutgoingConfiguration('common')
|
|
||||||
}
|
|
||||||
createJars('impl', sourceSets.main).configure {
|
|
||||||
it.createOutgoingConfiguration('common')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// For publishing
|
// For publishing
|
||||||
|
@ -7,11 +7,10 @@ plugins {
|
|||||||
id 'flywheel.package-infos'
|
id 'flywheel.package-infos'
|
||||||
id 'flywheel.subproject'
|
id 'flywheel.subproject'
|
||||||
id 'flywheel.platform'
|
id 'flywheel.platform'
|
||||||
|
id 'flywheel.jar-sets'
|
||||||
id 'flywheel.transitive-source-sets'
|
id 'flywheel.transitive-source-sets'
|
||||||
}
|
}
|
||||||
|
|
||||||
evaluationDependsOn(':common')
|
|
||||||
|
|
||||||
transitiveSourceSets {
|
transitiveSourceSets {
|
||||||
compileClasspath = sourceSets.main.compileClasspath
|
compileClasspath = sourceSets.main.compileClasspath
|
||||||
|
|
||||||
@ -33,33 +32,19 @@ transitiveSourceSets {
|
|||||||
createCompileConfigurations()
|
createCompileConfigurations()
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultPackageInfos {
|
platform {
|
||||||
forSourceSets sourceSets.api, sourceSets.lib, sourceSets.backend, sourceSets.main
|
commonProject = project(':common')
|
||||||
|
sources sourceSets.api, sourceSets.lib, sourceSets.backend, sourceSets.main
|
||||||
|
compileWithCommonSourceSets()
|
||||||
|
setupLoomMod()
|
||||||
|
setupLoomRuns()
|
||||||
|
setupFatJar()
|
||||||
|
publishMod()
|
||||||
|
publishRemap(apiArtifactId, jarSets.createJars('api', sourceSets.api, sourceSets.lib))
|
||||||
}
|
}
|
||||||
|
|
||||||
loom {
|
defaultPackageInfos {
|
||||||
runs {
|
sources sourceSets.api, sourceSets.lib, sourceSets.backend, sourceSets.main
|
||||||
client {
|
|
||||||
ideConfigGenerated true
|
|
||||||
|
|
||||||
// Turn on our own debug flags
|
|
||||||
property 'flw.dumpShaderSource', 'true'
|
|
||||||
property 'flw.debugMemorySafety', 'true'
|
|
||||||
|
|
||||||
// Turn on mixin debug flags
|
|
||||||
property 'mixin.debug.export', 'true'
|
|
||||||
property 'mixin.debug.verbose', 'true'
|
|
||||||
|
|
||||||
// 720p baby!
|
|
||||||
programArgs '--width', '1280', '--height', '720'
|
|
||||||
}
|
|
||||||
|
|
||||||
// We're a client mod, but we need to make sure we correctly render when playing on a server.
|
|
||||||
server {
|
|
||||||
ideConfigGenerated true
|
|
||||||
programArgs '--nogui'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -7,11 +7,10 @@ plugins {
|
|||||||
id 'flywheel.package-infos'
|
id 'flywheel.package-infos'
|
||||||
id 'flywheel.subproject'
|
id 'flywheel.subproject'
|
||||||
id 'flywheel.platform'
|
id 'flywheel.platform'
|
||||||
|
id 'flywheel.jar-sets'
|
||||||
id 'flywheel.transitive-source-sets'
|
id 'flywheel.transitive-source-sets'
|
||||||
}
|
}
|
||||||
|
|
||||||
evaluationDependsOn(':common')
|
|
||||||
|
|
||||||
transitiveSourceSets {
|
transitiveSourceSets {
|
||||||
compileClasspath = sourceSets.main.compileClasspath
|
compileClasspath = sourceSets.main.compileClasspath
|
||||||
|
|
||||||
@ -33,8 +32,19 @@ transitiveSourceSets {
|
|||||||
createCompileConfigurations()
|
createCompileConfigurations()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
platform {
|
||||||
|
commonProject = project(':common')
|
||||||
|
sources sourceSets.api, sourceSets.lib, sourceSets.backend, sourceSets.main
|
||||||
|
compileWithCommonSourceSets()
|
||||||
|
setupLoomMod()
|
||||||
|
setupLoomRuns()
|
||||||
|
setupFatJar()
|
||||||
|
publishMod()
|
||||||
|
publishRemap(apiArtifactId, jarSets.createJars('api', sourceSets.api, sourceSets.lib))
|
||||||
|
}
|
||||||
|
|
||||||
defaultPackageInfos {
|
defaultPackageInfos {
|
||||||
forSourceSets sourceSets.api, sourceSets.lib, sourceSets.backend, sourceSets.main
|
sources sourceSets.api, sourceSets.lib, sourceSets.backend, sourceSets.main
|
||||||
}
|
}
|
||||||
|
|
||||||
loom {
|
loom {
|
||||||
@ -49,27 +59,6 @@ loom {
|
|||||||
property 'forge.logging.markers', ''
|
property 'forge.logging.markers', ''
|
||||||
property 'forge.logging.console.level', 'debug'
|
property 'forge.logging.console.level', 'debug'
|
||||||
}
|
}
|
||||||
|
|
||||||
client {
|
|
||||||
ideConfigGenerated true
|
|
||||||
|
|
||||||
// Turn on our own debug flags
|
|
||||||
property 'flw.dumpShaderSource', 'true'
|
|
||||||
property 'flw.debugMemorySafety', 'true'
|
|
||||||
|
|
||||||
// Turn on mixin debug flags
|
|
||||||
property 'mixin.debug.export', 'true'
|
|
||||||
property 'mixin.debug.verbose', 'true'
|
|
||||||
|
|
||||||
// 720p baby!
|
|
||||||
programArgs '--width', '1280', '--height', '720'
|
|
||||||
}
|
|
||||||
|
|
||||||
// We're a client mod, but we need to make sure we correctly render when playing on a server.
|
|
||||||
server {
|
|
||||||
ideConfigGenerated true
|
|
||||||
programArgs '--nogui'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user