diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 40d8a06a0..c3c11c5ef 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -19,10 +19,14 @@ repositories { gradlePlugin { plugins { - simplePlugin { + platformPlugin { id = 'flywheel.platform' implementationClass = 'com.jozufozu.gradle.PlatformPlugin' } + outgoingConfigurationPlugin { + id = 'flywheel.outgoing-configuration' + implementationClass = 'com.jozufozu.gradle.OutgoingConfigurationPlugin' + } } } diff --git a/buildSrc/src/main/groovy/com/jozufozu/gradle/JarTaskSet.groovy b/buildSrc/src/main/groovy/com/jozufozu/gradle/JarTaskSet.groovy new file mode 100644 index 000000000..d14ed925c --- /dev/null +++ b/buildSrc/src/main/groovy/com/jozufozu/gradle/JarTaskSet.groovy @@ -0,0 +1,22 @@ +package com.jozufozu.gradle + +import net.fabricmc.loom.task.RemapJarTask +import net.fabricmc.loom.task.RemapSourcesJarTask +import org.gradle.api.tasks.TaskProvider +import org.gradle.api.tasks.bundling.Jar + +class JarTaskSet { + TaskProvider jar + TaskProvider remapJar + TaskProvider sources + TaskProvider remapSources + TaskProvider javadocJar + + JarTaskSet(TaskProvider jar, TaskProvider remapJar, TaskProvider sources, TaskProvider remapSources, TaskProvider javadocJar) { + this.jar = jar + this.remapJar = remapJar + this.sources = sources + this.remapSources = remapSources + this.javadocJar = javadocJar + } +} diff --git a/buildSrc/src/main/groovy/com/jozufozu/gradle/OutgoingConfigurationPlugin.groovy b/buildSrc/src/main/groovy/com/jozufozu/gradle/OutgoingConfigurationPlugin.groovy new file mode 100644 index 000000000..d23336943 --- /dev/null +++ b/buildSrc/src/main/groovy/com/jozufozu/gradle/OutgoingConfigurationPlugin.groovy @@ -0,0 +1,99 @@ +package com.jozufozu.gradle + +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.artifacts.ConfigurationContainer +import org.gradle.api.artifacts.dsl.ArtifactHandler +import org.gradle.api.tasks.SourceSet +import org.gradle.api.tasks.SourceSetContainer +import org.gradle.api.tasks.TaskContainer +import org.gradle.api.tasks.bundling.Jar +import org.gradle.api.tasks.javadoc.Javadoc + +class OutgoingConfigurationPlugin implements Plugin { + @Override + void apply(Project project) { + project.extensions.create("outgoing", Extension, project) + } + + static class Extension { + private final Project project + private final SourceSetContainer sourceSets + private final ConfigurationContainer configurations + private final TaskContainer tasks + private final ArtifactHandler artifacts + + Extension(Project project) { + this.project = project + this.sourceSets = project.getExtensions().getByType(SourceSetContainer) + this.configurations = project.configurations + this.tasks = project.tasks + this.artifacts = project.artifacts + } + + JarTaskSet createJarAndOutgoingConfiguration(String name) { + return createJarAndOutgoingConfiguration(name, sourceSets.named(name).get()) + } + + JarTaskSet createJarAndOutgoingConfiguration(String name, SourceSet... sourceSetSet) { + def config = configurations.register("common${name.capitalize()}") { + canBeConsumed = true + canBeResolved = false + } + def jarTask = tasks.register("${name}Jar", Jar) { + group = 'Build' + archiveClassifier.set(name) + destinationDirectory.set(project.layout.buildDirectory.dir('devlibs')) + for (SourceSet set in sourceSetSet) { + from set.output + } + } + def remapJarTask = tasks.register("${name}RemapJar", RemapJarTask) { + group = 'Loom' + dependsOn(jarTask) + archiveClassifier.set(name) + inputFile.set(jarTask.flatMap { it.archiveFile }) + } + def sourcesTask = tasks.register("${name}SourcesJar", Jar) { + group = 'Build' + archiveClassifier.set("${name}-sources") + destinationDirectory.set(project.layout.buildDirectory.dir('devlibs')) + for (SourceSet set in sourceSetSet) { + from set.allSource + } + } + def remapSourcesTask = tasks.register("${name}RemapSourcesJar", RemapSourcesJarTask) { + group = 'Loom' + dependsOn(sourcesTask) + archiveClassifier.set("${name}-sources") + inputFile.set(sourcesTask.flatMap { it.archiveFile }) + } + def javadocTask = tasks.register("${name}Javadoc", Javadoc) { + group = 'Build' + destinationDir = project.layout.buildDirectory.dir("docs/${name}-javadoc").get().asFile + options.encoding = 'UTF-8' + for (SourceSet set in sourceSetSet) { + source set.allJava + classpath += set.compileClasspath + } + } + def javadocJarTask = tasks.register("${name}JavadocJar", Jar) { + group = 'Build' + dependsOn(javadocTask) + archiveClassifier.set("${name}-javadoc") + destinationDirectory.set(project.layout.buildDirectory.dir('libs')) + from(javadocTask.map { it.outputs }) + } + + artifacts.add(config.name, jarTask) + + tasks.named('assemble').configure { + dependsOn(jarTask, remapJarTask, sourcesTask, remapSourcesTask, javadocTask, javadocJarTask) + } + + return new JarTaskSet(jarTask, remapJarTask, sourcesTask, remapSourcesTask, javadocJarTask) + } + } +} diff --git a/common/build.gradle b/common/build.gradle index 20a518168..c06a405a0 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -6,6 +6,7 @@ plugins { id 'flywheel.java' id 'flywheel.package-infos' id 'flywheel.subproject' + id 'flywheel.outgoing-configuration' } sourceSets { @@ -39,30 +40,31 @@ sourceSets { } } -TaskProvider createJarAndOutgoingConfiguration(String name) { - return createJarAndOutgoingConfiguration(name, sourceSets.named(name).get()) +jar { + from sourceSets.api.output + from sourceSets.lib.output + from sourceSets.backend.output + archiveClassifier.set('') } -TaskProvider createJarAndOutgoingConfiguration(String name, SourceSet sourceSet) { - def config = configurations.register("common${name.capitalize()}") { - canBeConsumed = true - canBeResolved = false - } - def jarTask = tasks.register("${name}Jar", Jar) { - archiveClassifier.set(name) - from sourceSet.output - } +sourcesJar { + from sourceSets.api.allSource + from sourceSets.lib.allSource + from sourceSets.backend.allSource +} - artifacts.add(config.name, jarTask) - - return jarTask +javadoc { + source sourceSets.api.allJava + source sourceSets.lib.allJava + source sourceSets.backend.allJava } // TODO: repackage these for maven publication -def apiJar = createJarAndOutgoingConfiguration("api") -def libJar = createJarAndOutgoingConfiguration("lib") -def backendJar = createJarAndOutgoingConfiguration("backend") -def implJar = createJarAndOutgoingConfiguration("impl", sourceSets.main) +outgoing.createJarAndOutgoingConfiguration("apiOnly", sourceSets.api) +outgoing.createJarAndOutgoingConfiguration("lib") +def apiLibJar = outgoing.createJarAndOutgoingConfiguration("api", sourceSets.api, sourceSets.lib) +def backendJar = outgoing.createJarAndOutgoingConfiguration("backend") +def implJar = outgoing.createJarAndOutgoingConfiguration("impl", sourceSets.main) dependencies { modCompileOnly "net.fabricmc:fabric-loader:${fabric_loader_version}" @@ -78,11 +80,30 @@ publishing { publications { register('mavenIntermediary', MavenPublication) { from(components['java']) + artifact apiLibJar.remapJar + artifact apiLibJar.remapSources + artifact apiLibJar.javadocJar + artifact backendJar.remapJar + artifact backendJar.remapSources + artifact backendJar.javadocJar + artifact implJar.remapJar + artifact implJar.remapSources + artifact implJar.javadocJar artifactId = "flywheel-${project.name}-intermediary-${artifact_minecraft_version}" } register('mavenMojmap', MavenPublication) { artifact jar artifact sourcesJar + artifact javadocJar + artifact apiLibJar.jar + artifact apiLibJar.sources + artifact apiLibJar.javadocJar + artifact backendJar.jar + artifact backendJar.sources + artifact backendJar.javadocJar + artifact implJar.jar + artifact implJar.sources + artifact implJar.javadocJar artifactId = "flywheel-${project.name}-mojmap-${artifact_minecraft_version}" } } diff --git a/fabric/build.gradle b/fabric/build.gradle index bcb20f5e5..4ae964468 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -43,7 +43,7 @@ dependencies { modCompileOnly "maven.modrinth:sodium:${sodium_version}" modCompileOnly "maven.modrinth:iris:${iris_version}" - forApi project(path: ':common', configuration: 'commonApi') + forApi project(path: ':common', configuration: 'commonApiOnly') forLib project(path: ':common', configuration: 'commonLib') forBackend project(path: ':common', configuration: 'commonBackend') forImpl project(path: ':common', configuration: 'commonImpl') diff --git a/forge/build.gradle b/forge/build.gradle index 2b7c0ce57..b6ef3166c 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -53,7 +53,7 @@ dependencies { modCompileOnly "maven.modrinth:embeddium:${embeddium_version}" modCompileOnly "maven.modrinth:oculus:${oculus_version}" - forApi project(path: ':common', configuration: 'commonApi') + forApi project(path: ':common', configuration: 'commonApiOnly') forLib project(path: ':common', configuration: 'commonLib') forBackend project(path: ':common', configuration: 'commonBackend') forImpl project(path: ':common', configuration: 'commonImpl')