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

Partially refactor to use more idiomatic Gradle (part 2) #242

Merged
merged 18 commits into from
Jul 14, 2023

Conversation

TWiStErRob
Copy link
Collaborator

@TWiStErRob TWiStErRob commented Jul 8, 2023

Following #241

Recommended to look at the changes commit by commit so the changes make more sense. In the general the goals were:

  • Remove constructor-injection, the Task should be reusable and self-contained, where the data is coming from (i.e. wiring) is the problem of the plugin, not the task.
  • Use the lazy and generated APIs as much as possible.
  • Minor cleanups while doing the above. (e.g. use Kotlin stdlib more, add groups/description for each task)

Breaking changes:

  • ReleaseNexusStagingRepository.setStagingRepositoryId renamed to setStagingRepositoryIdToRelease
  • CloseNexusStagingRepository.setStagingRepositoryId renamed to setStagingRepositoryIdToClose
  • All descendants of AbstractNexusStagingRepositoryTask have different constructors.

invalidateDescriptor has existed since Gradle 4.10 gradle/gradle@cea96d4

Side effect of this is that it'll throw NoSuchMethodException if the method is not found so the warning will show instead of just silently (?.) ignoring it.
Note: Gradle gets confused about a mutable property when generating the decorated code. Renaming the setters detaches it from the real property.

Example clash:
AbstractTransitionNexusStagingRepositoryTask.stagingRepositoryId -> getStagingRepositoryId: Property<String>
ReleaseNexusStagingRepository.setStagingRepositoryId -> setStagingRepositoryId(String)
together these two form a broken property.
Copy link
Collaborator Author

@TWiStErRob TWiStErRob left a comment

Choose a reason for hiding this comment

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

Few notes for reviewers.

Comment on lines 132 to 136
val findStagingRepository = rootProject.tasks.register<FindStagingRepository>(
"find${capitalizedName}StagingRepository",
rootProject.objects,
extension,
repository,
registry
)
findStagingRepository {
Copy link
Collaborator Author

@TWiStErRob TWiStErRob Jul 8, 2023

Choose a reason for hiding this comment

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

My goal was to merge each of these into:

val name = rootProject.tasks.register<T>("name") {
    ...
}

but these last two I can't figure out how to remove the registry.

I think the answer is using the build service (injecting it inside the task), but that's only possible from Gradle 6.1 (see NexusPublishPlugin.createRegistry) and the current minimum is 6.0.

@3flex any ideas?

Copy link
Collaborator Author

@TWiStErRob TWiStErRob Jul 13, 2023

Choose a reason for hiding this comment

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

Just moved from unannotated constructor property to @Internal managed property: e964697

Copy link
Contributor

@szpak szpak left a comment

Choose a reason for hiding this comment

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

Thanks @TWiStErRob. It looks good, I've just made a few nitpicking.

Btw, as my other plugins are still at the Gradle 6 level of "idiomaticity", @3flex maybe you could also take a look?

@TWiStErRob
Copy link
Collaborator Author

Btw, as my other plugins are still at the Gradle 6 level of "idiomaticity"

Btw, this is motivated by gradle/gradle#22348 and https://docs.google.com/document/d/1iZHN5mcN56IQtGOoR5GyH9NQLSOQLQ1SHN5ulNheDjc which is going towards "managed everything".

@TWiStErRob
Copy link
Collaborator Author

@szpak Ok, so in the end there were no changes necessary, the only finding you flagged was in uncommitted code 😅.

@TWiStErRob TWiStErRob requested a review from szpak July 11, 2023 15:48
@TWiStErRob
Copy link
Collaborator Author

TWiStErRob commented Jul 11, 2023

I consider this ready, pending a word from @3flex. Btw, that word could be "go ahead, I'm not going to review" too if you don't have time.

@szpak szpak mentioned this pull request Jul 13, 2023
@szpak szpak merged commit 66f3284 into gradle-nexus:master Jul 14, 2023
6 checks passed
@TWiStErRob
Copy link
Collaborator Author

Ugh, should I rebase and squash a few next time to not get so many random small commits to master?

@szpak
Copy link
Contributor

szpak commented Jul 14, 2023

Ugh, should I rebase and squash a few next time to not get so many random small commits to master?

No, I did it purposely. I wanted to keep some of those smaller changes (to maybe replicate in my other plugins ;) ). Sure, some commits could be squashed/rebased, but I didn't want to bother you.
In general, a "squash and commit" is a default strategy set for the project.

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