Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The default artifact will still be published even when an artifact ID has been explicitly specified. #309

Open
Goooler opened this issue Jan 25, 2024 · 9 comments

Comments

@Goooler
Copy link
Contributor

Goooler commented Jan 25, 2024

My config like this:

publishing {
    publications {
        create<MavenPublication>("mavenJava") {
            artifactId = "legacy-osgi-gradle-plugin"
            ...
        }
    }
}

artifactId has been declared explicitly, and the default project name is gradle-legacy-osgi-plugin, then publish it to MavenLocal:

13:08:30: Executing 'publishToMavenLocal --no-configuration-cache'...

> Task :compileJava FROM-CACHE
> Task :compileGroovy NO-SOURCE
> Task :pluginDescriptors
> Task :processResources
> Task :classes
> Task :jar
> Task :javadoc FROM-CACHE
> Task :javadocJar
> Task :sourcesJar
> Task :generateMetadataFileForMavenJavaPublication
> Task :generatePomFileForMavenJavaPublication
> Task :signMavenJavaPublication
> Task :generatePomFileForOsgiPluginPluginMarkerMavenPublication
> Task :signOsgiPluginPluginMarkerMavenPublication
> Task :generateMetadataFileForPluginMavenPublication
> Task :generatePomFileForPluginMavenPublication
> Task :signPluginMavenPublication
> Task :publishMavenJavaPublicationToMavenLocal
> Task :publishOsgiPluginPluginMarkerMavenPublicationToMavenLocal
> Task :publishPluginMavenPublicationToMavenLocal
> Task :publishToMavenLocal

BUILD SUCCESSFUL in 33s
18 actionable tasks: 16 executed, 2 from cache



tree ~/.m2/repository

/Users/snebula/.m2/repository
└── io
    └── github
        └── goooler
            └── osgi
                ├── gradle-legacy-osgi-plugin
                │   ├── 0.8.3-SNAPSHOT
                │   │   ├── gradle-legacy-osgi-plugin-0.8.3-SNAPSHOT-javadoc.jar
                │   │   ├── gradle-legacy-osgi-plugin-0.8.3-SNAPSHOT-javadoc.jar.asc
                │   │   ├── gradle-legacy-osgi-plugin-0.8.3-SNAPSHOT-sources.jar
                │   │   ├── gradle-legacy-osgi-plugin-0.8.3-SNAPSHOT-sources.jar.asc
                │   │   ├── gradle-legacy-osgi-plugin-0.8.3-SNAPSHOT.jar
                │   │   ├── gradle-legacy-osgi-plugin-0.8.3-SNAPSHOT.jar.asc
                │   │   ├── gradle-legacy-osgi-plugin-0.8.3-SNAPSHOT.module
                │   │   ├── gradle-legacy-osgi-plugin-0.8.3-SNAPSHOT.module.asc
                │   │   ├── gradle-legacy-osgi-plugin-0.8.3-SNAPSHOT.pom
                │   │   ├── gradle-legacy-osgi-plugin-0.8.3-SNAPSHOT.pom.asc
                │   │   └── maven-metadata-local.xml
                │   └── maven-metadata-local.xml
                ├── io.github.goooler.osgi.gradle.plugin
                │   ├── 0.8.3-SNAPSHOT
                │   │   ├── io.github.goooler.osgi.gradle.plugin-0.8.3-SNAPSHOT.pom
                │   │   ├── io.github.goooler.osgi.gradle.plugin-0.8.3-SNAPSHOT.pom.asc
                │   │   └── maven-metadata-local.xml
                │   └── maven-metadata-local.xml
                └── legacy-osgi-gradle-plugin
                    ├── 0.8.3-SNAPSHOT
                    │   ├── legacy-osgi-gradle-plugin-0.8.3-SNAPSHOT-javadoc.jar
                    │   ├── legacy-osgi-gradle-plugin-0.8.3-SNAPSHOT-javadoc.jar.asc
                    │   ├── legacy-osgi-gradle-plugin-0.8.3-SNAPSHOT-sources.jar
                    │   ├── legacy-osgi-gradle-plugin-0.8.3-SNAPSHOT-sources.jar.asc
                    │   ├── legacy-osgi-gradle-plugin-0.8.3-SNAPSHOT.jar
                    │   ├── legacy-osgi-gradle-plugin-0.8.3-SNAPSHOT.jar.asc
                    │   ├── legacy-osgi-gradle-plugin-0.8.3-SNAPSHOT.module
                    │   ├── legacy-osgi-gradle-plugin-0.8.3-SNAPSHOT.module.asc
                    │   ├── legacy-osgi-gradle-plugin-0.8.3-SNAPSHOT.pom
                    │   ├── legacy-osgi-gradle-plugin-0.8.3-SNAPSHOT.pom.asc
                    │   └── maven-metadata-local.xml
                    └── maven-metadata-local.xml

11 directories, 28 files

We just expect io.github.goooler.osgi.gradle.plugin and legacy-osgi-gradle-plugin here, but gradle-legacy-osgi-plugin has been published as well, which with the default project name.

Full config here Goooler/gradle-legacy-osgi-plugin@b941a21.

@TWiStErRob
Copy link
Collaborator

TWiStErRob commented Jan 25, 2024

Beautiful report!

Based on what you have in OP, I think this is WAI because we have 3 publications in the logs:

> Task :publishMavenJavaPublicationToMavenLocal
> Task :publishOsgiPluginPluginMarkerMavenPublicationToMavenLocal
> Task :publishPluginMavenPublicationToMavenLocal

and 3 artifacts in the folder.

  • The marker is correct
  • you're creating mavenJava as legacy...,
  • and there's a default pluginMaven publication which uses the gradle... project name.

Try to change to

named<MavenPublication>("pluginMaven").configure { ... }

(You might need afterEvaluate or matching to get the timing right. source) The timing issue seems fixed, so I need to review my workaround.

Btw, I think this issue is with id("com.gradle.plugin-publish") because this nexus plugin only sets up the sonatype tasks not the maveLocal ones. That said it would be the same issue just with harder visibility on folder contents.

@Goooler
Copy link
Contributor Author

Goooler commented Jan 26, 2024

Seems can't:

Publication with name 'pluginMaven' not found.

publishing.publications is empty.

@TWiStErRob
Copy link
Collaborator

even in afterEvaluate?

@Goooler
Copy link
Contributor Author

Goooler commented Jan 28, 2024

publishing {
    publications {
        afterEvaluate {
            named<MavenPublication>("pluginMaven") {
                ...
            }
        }
    }
}
FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'gradle-legacy-osgi-plugin'.
> Maven publication 'pluginMaven' cannot include multiple components

@TWiStErRob
Copy link
Collaborator

That's so weird, looking.

@TWiStErRob
Copy link
Collaborator

Ah, the error is not that it's not found, but it by default includes the Java component, see org.gradle.plugin.devel.plugins.MavenPluginPublishPlugin.

Here's what I would go with: use all the built-ins and no workarounds needed: publishing.patch (delete all the commented lines when applying, they're just for you, keep // Pre-configure ...)

Docs:

@Goooler
Copy link
Contributor Author

Goooler commented Jan 28, 2024

Thanks a lot! It works for me now.

Should we note this in README or fallback it?

@TWiStErRob
Copy link
Collaborator

I'm not sure what we could add, @szpak thoughts?

Note: this plugin is a generic publishing plugin, publishing Gradle plugins still uses all the same facilities, except Gradle provided plugin does most of the wiring that's still required for normal library jars.

I think this might need a full rewrite of the readme, giving examples for the most common use cases, so it's easier for people to copy-paste when they don't know/want to know the details?

@szpak
Copy link
Contributor

szpak commented Jan 29, 2024

I would agree with Rob, that it's rather a problem with the generic publishing configuration in Gradle.

Do you have a good idea/proposal how the new README could look like? We could also fold some sections to make it easier to read (and to find the basic cases).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants