modmuss50 / mod-publish-plugin

A Gradle plugin to publish mods to a range of destinations
https://modmuss50.github.io/mod-publish-plugin/
MIT License
56 stars 9 forks source link

Programmatically setting dependencies from the calling project's properties? #42

Closed gniftygnome closed 6 months ago

gniftygnome commented 6 months ago

I was doing this (which I gather was limited to setting only one of the values):

        if (project.hasProperty("modrinth_required_dependencies")) {
            project.modrinth_required_dependencies.split(", ").each {
                requires {
                    slug = it
                }
            }
        }

Today I tried to get it working again with later MPP versions, and arrived at this:

        if (project.hasProperty("modrinth_required_dependencies")) {
            requires(project.modrinth_required_dependencies.split(", "))
        }

However, the requires function does not exist; I assume because of a type mismatch. Is there a reasonable way to achieve what I am trying to do here?

gniftygnome commented 6 months ago
        if (project.hasProperty("modrinth_required_dependencies")) {
            project.getProperty("modrinth_required_dependencies").split(',').map(String::trim).filter(String::isNotEmpty).each {
                requires(it)
            }
        }

gives

...
Caused by: groovy.lang.MissingMethodException: No signature of method: [Ljava.lang.String;.map() is applicable for argument types: (org.codehaus.groovy.runtime.MethodClosure) values: [org.codehaus.groovy.runtime.MethodClosure@310147de]
Possible solutions: max(), max(groovy.lang.Closure), max(java.util.Comparator), tap(groovy.lang.Closure), min(), min(groovy.lang.Closure)
    at ferry_mpp_43cy8rxk6t6h3xo6gtpgjvata$_run_closure1.doCall(https://raw.githubusercontent.com/TerraformersMC/GradleScripts/3.0-beta/ferry-mpp.gradle:110)
...

Which is definitely a type issue, but also greek to me.

gniftygnome commented 6 months ago

Nevermind ... I finally figured out something that seems to work.

String[] splitProperty(String property) {
    String value = project.findProperty(property)

    if (value == null) {
        return new String[0];
    }

    return value.split(', *').findAll { !it.isBlank() }
}
//...
        modrinth {
            splitProperty("modrinth_required_dependencies").each {
                requires(it)
            }
        }
gniftygnome commented 6 months ago

And here I had issue 42 and I didn't even thank you for all the fish...