Get Publishing!

This commit is contained in:
Kneelawk 2024-04-26 22:14:14 -07:00 committed by Jozufozu
parent d5bdbeb106
commit d88933984e
3 changed files with 124 additions and 118 deletions

View file

@ -0,0 +1,90 @@
package com.jozufozu.gradle
import net.fabricmc.loom.task.RemapJarTask
import net.fabricmc.loom.task.RemapSourcesJarTask
import org.gradle.api.Project
import org.gradle.api.file.DuplicatesStrategy
import org.gradle.api.file.FileCopyDetails
import org.gradle.api.tasks.AbstractCopyTask
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.SourceTask
import org.gradle.api.tasks.bundling.Jar
import org.gradle.api.tasks.javadoc.Javadoc
class JarTaskUtils {
// We have duplicate packages between the common and platform dependent subprojects.
// In theory the package-info.java files should be identical, so just take the first one we find.
static void excludeDuplicatePackageInfos(AbstractCopyTask copyTask) {
copyTask.filesMatching('**/package-info.java') { FileCopyDetails details ->
details.duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
}
// The compile/javadoc tasks have a different base type that isn't so smart about exclusion handling.
static void excludeDuplicatePackageInfos(SourceTask sourceTask) {
sourceTask.exclude('**/package-info.java')
}
static JarTaskSet createJarAndOutgoingConfiguration(Project project, String name, SourceSet... sourceSetSet) {
def config = project.configurations.register("common${name.capitalize()}") {
canBeConsumed = true
canBeResolved = false
}
def jarTask = project.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
}
excludeDuplicatePackageInfos(it)
}
def remapJarTask = project.tasks.register("${name}RemapJar", RemapJarTask) {
group = 'Loom'
dependsOn(jarTask)
archiveClassifier.set(name)
inputFile.set(jarTask.flatMap { it.archiveFile })
}
def sourcesTask = project.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
}
excludeDuplicatePackageInfos(it)
}
def remapSourcesTask = project.tasks.register("${name}RemapSourcesJar", RemapSourcesJarTask) {
group = 'Loom'
dependsOn(sourcesTask)
archiveClassifier.set("${name}-sources")
inputFile.set(sourcesTask.flatMap { it.archiveFile })
}
def javadocTask = project.tasks.register("${name}Javadoc", Javadoc) {
group = 'Build'
destinationDir = project.layout.buildDirectory.dir("docs/${name}-javadoc").get().asFile
options.encoding = 'UTF-8'
options.optionFiles(project.rootProject.file('javadoc-options.txt'))
for (SourceSet set in sourceSetSet) {
source set.allJava
classpath += set.compileClasspath
}
excludeDuplicatePackageInfos(it)
}
def javadocJarTask = project.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 })
}
project.artifacts.add(config.name, jarTask)
project.tasks.named('assemble').configure {
dependsOn(jarTask, remapJarTask, sourcesTask, remapSourcesTask, javadocTask, javadocJarTask)
}
return new JarTaskSet(jarTask, remapJarTask, sourcesTask, remapSourcesTask, javadocJarTask)
}
}

View file

@ -1,16 +1,10 @@
package com.jozufozu.gradle 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.Plugin
import org.gradle.api.Project 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.SourceSet
import org.gradle.api.tasks.SourceSetContainer 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<Project> { class OutgoingConfigurationPlugin implements Plugin<Project> {
@Override @Override
@ -20,81 +14,17 @@ class OutgoingConfigurationPlugin implements Plugin<Project> {
static class Extension { static class Extension {
private final Project project private final Project project
private final SourceSetContainer sourceSets
private final ConfigurationContainer configurations
private final TaskContainer tasks
private final ArtifactHandler artifacts
Extension(Project project) { Extension(Project project) {
this.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) { JarTaskSet createJarAndOutgoingConfiguration(String name) {
return createJarAndOutgoingConfiguration(name, sourceSets.named(name).get()) return createJarAndOutgoingConfiguration(name, project.getExtensions().getByType(SourceSetContainer).named(name).get())
} }
JarTaskSet createJarAndOutgoingConfiguration(String name, SourceSet... sourceSetSet) { JarTaskSet createJarAndOutgoingConfiguration(String name, SourceSet... sourceSetSet) {
def config = configurations.register("common${name.capitalize()}") { return JarTaskUtils.createJarAndOutgoingConfiguration(project, name, sourceSetSet)
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'
options.optionFiles(project.rootProject.file('javadoc-options.txt'))
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)
} }
} }
} }

View file

@ -2,19 +2,14 @@ package com.jozufozu.gradle
import groovy.transform.CompileStatic import groovy.transform.CompileStatic
import net.fabricmc.loom.api.LoomGradleExtensionAPI import net.fabricmc.loom.api.LoomGradleExtensionAPI
import net.fabricmc.loom.task.RemapJarTask
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.artifacts.Configuration import org.gradle.api.artifacts.Configuration
import org.gradle.api.file.DuplicatesStrategy
import org.gradle.api.file.FileCollection import org.gradle.api.file.FileCollection
import org.gradle.api.file.FileCopyDetails
import org.gradle.api.publish.PublishingExtension import org.gradle.api.publish.PublishingExtension
import org.gradle.api.tasks.AbstractCopyTask import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.SourceSet import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.SourceSetContainer import org.gradle.api.tasks.SourceSetContainer
import org.gradle.api.tasks.SourceTask
import org.gradle.api.tasks.bundling.Jar import org.gradle.api.tasks.bundling.Jar
import org.gradle.api.tasks.compile.JavaCompile import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.api.tasks.javadoc.Javadoc import org.gradle.api.tasks.javadoc.Javadoc
@ -87,23 +82,14 @@ class PlatformPlugin implements Plugin<Project> {
def tasks = project.tasks def tasks = project.tasks
tasks.withType(JavaCompile).configureEach { JavaCompile compileJava -> tasks.withType(JavaCompile).configureEach { JavaCompile compileJava ->
excludeDuplicatePackageInfos(compileJava) JarTaskUtils.excludeDuplicatePackageInfos(compileJava)
}
def apiJar = tasks.register('apiJar', Jar) { Jar jar ->
jar.archiveClassifier.set('api-dev')
jar.from platformApi.output, platformLib.output
jar.destinationDirectory.set(project.layout.buildDirectory.dir('devlibs'))
excludeDuplicatePackageInfos(jar)
} }
tasks.named('jar', Jar).configure { Jar jar -> tasks.named('jar', Jar).configure { Jar jar ->
jar.archiveClassifier.set('dev') jar.archiveClassifier.set('dev')
jar.from platformApi.output, platformLib.output, platformBackend.output jar.from platformApi.output, platformLib.output, platformBackend.output
excludeDuplicatePackageInfos(jar) JarTaskUtils.excludeDuplicatePackageInfos(jar)
} }
tasks.named('javadoc', Javadoc).configure { Javadoc javadoc -> tasks.named('javadoc', Javadoc).configure { Javadoc javadoc ->
@ -111,7 +97,7 @@ class PlatformPlugin implements Plugin<Project> {
javadoc.source platformApi.allJava, platformLib.allJava, platformBackend.allJava javadoc.source platformApi.allJava, platformLib.allJava, platformBackend.allJava
excludeDuplicatePackageInfos(javadoc) JarTaskUtils.excludeDuplicatePackageInfos(javadoc)
} }
tasks.named('sourcesJar', Jar).configure { Jar jar -> tasks.named('sourcesJar', Jar).configure { Jar jar ->
@ -119,33 +105,33 @@ class PlatformPlugin implements Plugin<Project> {
jar.from platformApi.allJava, platformLib.allJava, platformBackend.allJava jar.from platformApi.allJava, platformLib.allJava, platformBackend.allJava
excludeDuplicatePackageInfos(jar) JarTaskUtils.excludeDuplicatePackageInfos(jar)
} }
def remapApiJar = tasks.register('remapApiJar', RemapJarTask) { RemapJarTask remapJar -> // for if we decide to have Vanillin be another subproject, we can just use the exported configurations
remapJar.dependsOn(apiJar) JarTaskUtils.createJarAndOutgoingConfiguration(project, 'apiOnly', platformApi)
remapJar.inputFile.set(apiJar.flatMap { it.archiveFile }) JarTaskUtils.createJarAndOutgoingConfiguration(project, 'lib', platformLib)
remapJar.archiveClassifier.set('api')
JarTaskSet apiSet = JarTaskUtils.createJarAndOutgoingConfiguration(project, 'api', platformApi, platformLib)
JarTaskSet backendSet = JarTaskUtils.createJarAndOutgoingConfiguration(project, 'backend', platformBackend)
JarTaskSet implSet = JarTaskUtils.createJarAndOutgoingConfiguration(project, 'impl', platformImpl)
publishing.publications {
// we should be using remapped on both Fabric and Forge because Forge needs to put things in srg
it.register('mavenIntermediary', MavenPublication) { MavenPublication pub ->
pub.from(project.components.named('java').get())
pub.artifact(apiSet.remapJar)
pub.artifact(apiSet.remapSources)
pub.artifact(apiSet.javadocJar)
pub.artifact(backendSet.remapJar)
pub.artifact(backendSet.remapSources)
pub.artifact(backendSet.javadocJar)
pub.artifact(implSet.remapJar)
pub.artifact(implSet.remapSources)
pub.artifact(implSet.javadocJar)
pub.artifactId = "flywheel-${project.name}-${project.property('artifact_minecraft_version')}"
}
} }
def remapJar = tasks.named('remapJar', RemapJarTask)
tasks.named('build').configure { Task build ->
build.dependsOn(remapApiJar)
}
}
// We have duplicate packages between the common and platform dependent subprojects.
// In theory the package-info.java files should be identical, so just take the first one we find.
static void excludeDuplicatePackageInfos(AbstractCopyTask copyTask) {
copyTask.filesMatching('**/package-info.java') { FileCopyDetails details ->
details.duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
}
// The compile/javadoc tasks have a different base type that isn't so smart about exclusion handling.
static void excludeDuplicatePackageInfos(SourceTask sourceTask) {
sourceTask.exclude('**/package-info.java')
} }
static Configuration newConfiguration(Project project, String name) { static Configuration newConfiguration(Project project, String name) {
@ -156,9 +142,9 @@ class PlatformPlugin implements Plugin<Project> {
} }
static void extendsFrom(Project project, String name, Configuration... configurations) { static void extendsFrom(Project project, String name, Configuration... configurations) {
project.configurations.named(name).configure { project.configurations.named(name).configure {
it.extendsFrom(configurations) it.extendsFrom(configurations)
} }
} }
static void includeFromCommon(Project project, SourceSet sourceSet, SourceSet commonSourceSet) { static void includeFromCommon(Project project, SourceSet sourceSet, SourceSet commonSourceSet) {