TheMrMilchmann / gradle-curseforge-publish

A Gradle plugin that provides support for publishing artifacts to CurseForge.
https://plugins.gradle.org/plugin/io.github.themrmilchmann.curseforge-publish
MIT License
4 stars 0 forks source link

Does not work on Fabric Loom, Gradle 8.8, Java 17 #37

Open rikka0w0 opened 4 months ago

rikka0w0 commented 4 months ago

The following is my build.gradle:

plugins {
    id 'fabric-loom' version '1.7-SNAPSHOT'
    id 'maven-publish'
    id 'io.github.themrmilchmann.curseforge-publish' version '0.6.1'
}

curseforge {
    apiToken = 'MY_TOKEN'
    publications {
        register("curseForge") {
            projectId = "336554"

            artifacts.register("main") {
                from(tasks.named("remapJar"))
            }
        }
    }
}
System.out.println(curseforge.publications.getByName("curseForge").projectId.get())

When I run, it get:

.\gradlew.bat publishToCurseForge
To honour the JVM settings for this build a single-use Daemon process will be forked. For more on this, please refer to https://docs.gradle.org/8.8/userguide/gradle_daemon.html#sec:disabling_the_daemon in the Gradle documentation.
Daemon will be stopped at the end of the build

> Configure project :
Fabric Loom: 1.7.2
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
336554

> Task :publishFabricPublicationToCurseForge FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':publishFabricPublicationToCurseForge'.
> Cannot query the value of property 'projectId' because it has no value available.

The System.out.println prints the correct projected, but curseforge-publish cannot recognize it.

TheMrMilchmann commented 4 months ago

Hi @rikka0w0, when the plugin is used together with mod development plugins (such as Loom, or NeoGradle), preconfigured publications with the appropriate artifacts are created automatically. You can read more about this in the Interoperability section of the README.

In your case, you'll want to change the configuration of your publication too:

curseforge {
    publications {
        named("fabric") {
            projectId = "336554"

            artifacts.named("main") {
                // No need to add the jar here. It is preconfigured.
                // ...
            }
        }
    }
}

Specifically, the section about Loom interop will be of interest to you.

Also, here is an example of how I configure the publication for one of my mods.

rikka0w0 commented 3 months ago

Thanks!

This script snippet solves the projectId not available issue. However, if I have the changelog section, it fails with Could not determine the dependencies of task ':publishFabricPublicationToCurseForge'.. Without it, the script works. My curseforge section now looks like this:

curseforge {
    apiToken="SECRETE"
    publications {
        named("fabric") {
            projectId = "336554"

            artifacts.named("main") {
                displayName = "${project.minecraft_version}-${project.mod_version}-fabric"
                releaseType = ReleaseType.BETA

                changelog {
                    format = ChangelogFormat.MARKDOWN
                    from(file('build/info/CHANGELOG_FULL.md'))
                }
            }
        }
    }
}

May I ask one more question? How to specify the dependencies? I read that I need to use "slug" instead of projectId to specify dependencies. How could I find the slug? For example, my mod depends on Fabric API.

Does the Loom integration automatically locate the dependencies? I would like to know how to manually specify the versions of the dependencies.

Thanks in advance!

TheMrMilchmann commented 3 months ago

What's happening here is that you're using the from(...) function from CurseForgePublicationArtifact (which is used to specify the artifact file) instead of setting the changelog's content.

I assume you followed an example from the README which is currently wrong (See #38). Instead, you should declare the changelog as follows:

changelog {
    format = ...
    content = file('build/info/CHANGELOG_FULL.md").readText()
}

I think the Groovy equivalent is content = file('build/info/CHANGELOG_FULL.md').text.

May I ask one more question? How to specify the dependencies? I read that I need to use "slug" instead of projectId to specify dependencies. How could I find the slug? For example, my mod depends on Fabric API.

The slug is part of the URL of your mods CurseForge page:

https://www.curseforge.com/minecraft/mc-mods/{slug}

For example, for https://www.curseforge.com/minecraft/mc-mods/fabric-api the slug would be fabric-api.

Does the Loom integration automatically locate the dependencies

No, this is currently not possible since information about CurseForge publications is not available in mod artifacts.

I would like to know how to manually specify the versions of the dependencies.

CurseForge does not support dependencies on specific versions of a mod.

rikka0w0 commented 3 months ago

For example, for https://www.curseforge.com/minecraft/mc-mods/fabric-api the slug would be fabric-api.

Thanks! The dependency part is now working.

However, if I have releaseType = ReleaseType.BETA or changelog { format = ChangelogFormat.MARKDOWN }, the same error happens:

* What went wrong:
Could not determine the dependencies of task ':publishFabricPublicationToCurseForge'.
> Could not create domain object 'main' (CurseForgePublicationArtifact)

If I only have changelog { file('build/info/CHANGELOG_FULL.md').text }, the publish works as expected. I'm pretty sure that releaseType = ReleaseType.BETA is causing the issue.

This is my current working script.

curseforge {
    apiToken="SECRETE"
    publications {
        named("fabric") {
            projectId = "336554"

            artifacts.named("main") {
                displayName = "${project.minecraft_version}-${project.mod_version}-fabric"
                // releaseType = ReleaseType.BETA

                changelog {
                    //format = ChangelogFormat.MARKDOWN
                    content = file('build/info/CHANGELOG_FULL.md').text
                }

                relations {
                    requiredDependency("fabric-api")
                }
            }
        }
    }
}
TheMrMilchmann commented 3 months ago

For example, for https://www.curseforge.com/minecraft/mc-mods/fabric-api the slug would be fabric-api.

Thanks! The dependency part is now working.

However, if I have releaseType = ReleaseType.BETA or changelog { format = ChangelogFormat.MARKDOWN }, the same error happens:

* What went wrong:
Could not determine the dependencies of task ':publishFabricPublicationToCurseForge'.
> Could not create domain object 'main' (CurseForgePublicationArtifact)

If I only have changelog { file('build/info/CHANGELOG_FULL.md').text }, the publish works as expected. I'm pretty sure that releaseType = ReleaseType.BETA is causing the issue.

This is my current working script.

curseforge {
  apiToken="SECRETE"
  publications {
      named("fabric") {
          projectId = "336554"

          artifacts.named("main") {
              displayName = "${project.minecraft_version}-${project.mod_version}-fabric"
              // releaseType = ReleaseType.BETA

              changelog {
                  //format = ChangelogFormat.MARKDOWN
                  content = file('build/info/CHANGELOG_FULL.md').text
              }

              relations {
                  requiredDependency("fabric-api")
              }
          }
      }
  }
}

After further testing, I can't reproduce the error you are having. It would be great if you could share more details about your build setup or provide an MCVE.

NyakoFox commented 2 months ago

I'd like to mention I'm also having this issue, where ReleaseType.BETA doesn't seem to work.

TheMrMilchmann commented 2 months ago

After looking at @NyakoFox's project linked in #52, I wonder if you import the required types. When referencing either ChangelogFormat or ReleaseType, make sure to add the required import (import io.github.themrmilchmann.gradle.publish.curseforge.*) add the top of your build scripts.

IDEA seems to struggle a bit with suggesting that in Groovy.