hello, everyone, I want to use the same maven publ...
# gradle
l
hello, everyone, I want to use the same maven publish gradle kts file in the multi module project, I wrote the below
publish.gradle.kts
in my root project.
Copy code
apply(plugin = "maven-publish")

publishing {
    publications {
        create<MavenPublication>("mavenJava") {
            from(components["java"])
        }
    }
    repositories {
        maven {
            url = uri(extra["NEXUS_MAVEN_REPO_URL"] as String)
            isAllowInsecureProtocol = true
            credentials {
                username = extra["NEXUS_MAVEN_USERNAME"] as String
                password = extra["NEXUS_MAVEN_PASSWORD"] as String
            }
        }
    }
}
Then i include it in my module
build.gradle.kts
like below
Copy code
apply("../publish.gradle.kts")
Then i sync the project, it shows the below error, so how to fix it? The gradle version is
8.7
Expression 'publishing' cannot be invoked as a function. The function 'invoke()' is not found
c
it’s a little bit more complicated. you’ll need to move your script to become a “pre-compiled script plugin” and apply it as a plugin. https://docs.gradle.org/current/userguide/writing_plugins.html#pre_compiled_script_plugin
🫡 1
v
Which difference do I describe there? Between precompiled script plugin and convention plugin? ... No Between precompiled script plugin and traditional binary plugin? ... Yes "Convention plugin" just means that it is a plugin that employs you own conventions. This can be implemented as legacy script plugin, precompiled script plugin, traditional binary plugin, ... Doesn't matter. But the suggested solution was a good one. In discouraged legacy script plugins (the things you apply with "from"), you do not get type-safe accessors like
publishing { ... }
. Those you only get in build scripts and precompiled script plugins, and only for plugins that are applied in the recommended
plugins { ... }
block, and only for things those plugins add unconditionally. So yeah, a convention plugin in
buildSrc
or - what I prefer - in an included build, for example implemented as precompiled script plugin is the proper way to reuse build logic.
🫡 1