FabricMC / fabric-loom

Gradle build system plugin used to automate the setup of a minecraft mod development environment.
MIT License
223 stars 194 forks source link

Split environment source sets break source code publication #1083

Closed voidpointer0x00 closed 2 months ago

voidpointer0x00 commented 3 months ago

The gradle publish (both publishToMavenLocal and publishAllPublicationsToMavenRepository) does not publish generated sources jar when using splitEnvironmentSourceSets(). Though it does publish javadocs.

loom {
    splitEnvironmentSourceSets()

    mods {
        "demo-actions" {
            sourceSet sourceSets.main
            sourceSet sourceSets.client
        }
    }
}
/home/void/.m2/repository/com/pkg/demo-actions/1.0.2-alpha/
├── demo-actions-1.0.2-alpha.jar
├── demo-actions-1.0.2-alpha-javadoc.jar
├── demo-actions-1.0.2-alpha.module
└── demo-actions-1.0.2-alpha.pom
Full config (without some dependencies and repositories) ```groovy plugins { id 'fabric-loom' version '1.6-SNAPSHOT' id 'maven-publish' id 'io.freefair.lombok' version '8.6' id 'com.google.protobuf' version '0.9.4' } version = project.mod_version group = project.maven_group base { archivesName = "${project.archives_base_name}-${project.minecraft_version}" } loom { splitEnvironmentSourceSets() mods { "demo-actions" { sourceSet sourceSets.main sourceSet sourceSets.client } } } dependencies { minecraft "com.mojang:minecraft:${project.minecraft_version}" mappings loom.officialMojangMappings() modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" } processResources { inputs.property "version", project.version filesMatching("fabric.mod.json") { expand "version": project.version } } tasks.withType(JavaCompile).configureEach { it.options.release = 21 } java { withSourcesJar() withJavadocJar() sourceCompatibility = JavaVersion.VERSION_21 targetCompatibility = JavaVersion.VERSION_21 } publishing { publications { mavenJava(MavenPublication) { from components.java } } repositories { maven { url 'hidden' credentials { /* hidden */ } } } } ```

Removing the loom section and merging server & source code together makes -sources.jar publication possible, but it is definitely not a fix :D

It looks like it just skips source generation on publishing

> Configure project :
Fabric Loom: 1.6.3

> Task :extractIncludeProto UP-TO-DATE
> Task :extractProto UP-TO-DATE
> Task :generateProto UP-TO-DATE
> Task :processResources
> Task :generateEffectiveLombokConfig
> Task :compileJava UP-TO-DATE
> Task :classes
> Task :extractClientProto UP-TO-DATE
> Task :extractIncludeClientProto UP-TO-DATE
> Task :generateClientProto NO-SOURCE
> Task :processClientResources UP-TO-DATE
> Task :remapSourcesJar SKIPPED
> Task :generatePomFileForMavenJavaPublication
> Task :generateClientEffectiveLombokConfig
> Task :compileClientJava UP-TO-DATE
> Task :jar
> Task :remapJar
> Task :generateMetadataFileForMavenJavaPublication
> Task :publishMavenJavaPublicationToMavenLocal
> Task :publishToMavenLocal

BUILD SUCCESSFUL in 10s
16 actionable tasks: 8 executed, 8 up-to-date

With source sets merged:

> Configure project :
Fabric Loom: 1.6.3

> Task :generateEffectiveLombokConfig UP-TO-DATE
> Task :extractIncludeProto UP-TO-DATE
> Task :extractProto UP-TO-DATE
> Task :generateProto UP-TO-DATE
> Task :compileJava
> Task :processResources
> Task :classes
> Task :delombok UP-TO-DATE
> Task :javadoc UP-TO-DATE
> Task :javadocJar UP-TO-DATE
> Task :jar
> Task :sourcesJar UP-TO-DATE
> Task :remapSourcesJar UP-TO-DATE
> Task :generatePomFileForMavenJavaPublication
> Task :remapJar
> Task :generateMetadataFileForMavenJavaPublication
> Task :publishMavenJavaPublicationToMavenLocal
> Task :publishToMavenLocal

BUILD SUCCESSFUL in 13s
16 actionable tasks: 7 executed, 9 up-to-date
modmuss50 commented 3 months ago

Should now be fixed with the latest 1.6 build, let me know if there are still any problems 👍

voidpointer0x00 commented 2 months ago

Should now be fixed with the latest 1.6 build, let me know if there are still any problems 👍

Then I reverted to split sources, confirmed that -sources jars were published, but they were not recognized by IDEs. And only now I got my hands on looking into it :rofl:

So the problem seems to be that it publishes -sources jar identical to the regular with .class files. Also javadocs are ignored when publishing, maybe related?

md5 comparison of local build files to the files in maven repo 1) with split sources, 2) sources merged without loom's splitEnvironmentSourceSets:

# maven repo
9a0e810d8cb35e54365ba9d0f4e4dff5  demo-actions-1.1.4.jar
9a0e810d8cb35e54365ba9d0f4e4dff5  demo-actions-1.1.4-sources.jar # contains .class files
# local build files
9a0e810d8cb35e54365ba9d0f4e4dff5  build/libs/demo-actions-1.20.1-1.1.4.jar
b7f885ad473af2ce5e87cf5eb181f382  build/libs/demo-actions-1.20.1-1.1.4-sources.jar # contains .java files
# merged sources, works as intended; maven repo:
ef322d9e98d986b899f885afe44464be  demo-actions-1.1.5.jar
e65e318665c6d9887de8f6509deffb19  demo-actions-1.1.5-sources.jar
# local build files:
ef322d9e98d986b899f885afe44464be  build/libs/demo-actions-1.20.1-1.1.5.jar
1b9fa928e0c3f0d162462a295784c30b  build/libs/demo-actions-1.20.1-1.1.5-javadoc.jar # not published?
e65e318665c6d9887de8f6509deffb19  build/libs/demo-actions-1.20.1-1.1.5-sources.jar
modmuss50 commented 2 months ago

Fixed again 👍