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

fix: resolve issue with attempting to register a task by the same name more than once. #677

Conversation

autonomousapps
Copy link
Contributor

I wasn't sure what the best resolution was to the problem I faced, so I figured it would be best to just show a PR and we could discuss. This is the error I ran into in my (closed source) project:

Caused by: org.gradle.api.internal.tasks.DefaultTaskContainer$DuplicateTaskException: Cannot add task 'simpleJavadocJar' as a task with that name already exists.
at org.gradle.api.internal.tasks.DefaultTaskContainer.failOnDuplicateTask(DefaultTaskContainer.java:257)	
•••
at com.vanniktech.maven.publish.tasks.JavadocJar$Companion.plainJavadocJar(JavadocJar.kt:27)	
at com.vanniktech.maven.publish.tasks.JavadocJar$Companion.javadocJarTask$plugin(JavadocJar.kt:19)	
at com.vanniktech.maven.publish.GradlePlugin$configure$1$1.invoke(Platform.kt:85)	
at com.vanniktech.maven.publish.GradlePlugin$configure$1$1.invoke(Platform.kt:85)	
at com.vanniktech.maven.publish.PlatformKt.withJavadocJar(Platform.kt:444)	
at com.vanniktech.maven.publish.PlatformKt.access$withJavadocJar(Platform.kt:1)	
at com.vanniktech.maven.publish.GradlePlugin.configure$lambda$0(Platform.kt:85)	
at com.vanniktech.maven.publish.ProjectExtensionsKt.mavenPublicationsWithoutPluginMarker$lambda$0(ProjectExtensions.kt:32)

I did a bit of tracing and it looks like you're iterating over every publication in a project, and then adding one of the tasks for each. I have a plugin to support testing gradle plugins that also adds a publication for test purposes.

@gabrielittner
Copy link
Collaborator

I think I probably just made the assumption that a java-gradle-plugin project only has the default publications that are created automatically and that there is just one publication that isn't a plugin marker.

As an alternative we could move the javadocJarTask call outside of the loop. There isn't a scenario with 0 publications for which we'd then create an unneeded task. KMP projects already use that approach.

@autonomousapps
Copy link
Contributor Author

As an alternative we could move the javadocJarTask call outside of the loop.

I can give this a try. Thanks for the review!

@autonomousapps
Copy link
Contributor Author

Actually, should we pull this out of the loop for all platforms? I ran into the issue with a gradle plugin, but it might happen in other cases?

If you prefer to see that happen in the real world before making such a change, I understand.

Copy link
Collaborator

@gabrielittner gabrielittner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix

Actually, should we pull this out of the loop for all platforms? I ran into the issue with a gradle plugin, but it might happen in other cases?

If I didn't miss anything the plugin is only looping over publications for Gradle plugins and KMP. For the other platforms the underying plugins don't create publications automatically, so the plugin is creating one manually and only creates the task there.

@gabrielittner gabrielittner merged commit 32e971a into vanniktech:main Dec 9, 2023
9 checks passed
@autonomousapps autonomousapps deleted the trobalik.duplicate-task-exception branch December 9, 2023 18:15
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

Successfully merging this pull request may close these issues.

2 participants