Type-safe accessor for plugin added artifacts

I have a custom Gradle plugin which adds a configuration and artifact to the project.
Is it possible to reference such an artifact from the project’s build.gradle.kts in a type-safe manner?

publishing {
    publications {
        create<MavenPublication>("myPublication") {
            groupId = "com.acme"
            version = "1.0.0"
            artifactId = "myArtifact"
            // TODO (rodedb): Is there no way to make this typesafe by referencing the existing artifact directly?

Thank you.

I think what you want is artifact(tasks.distTar).
That should then also imply the necessary task dependency.

Thanks for the reply.

So this is basically like saying that the artifact will be the distTar task’s output?

Exactly. And it is always preferable to write outputs to inputs instead of configuring paths.

Understood. Thanks again.

1 Like