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

repositories function clashes with Project.repositories from the Kotlin DSL (Gradle 8.1) #220

Closed
szpak opened this issue May 7, 2023 · 22 comments
Labels

Comments

@szpak
Copy link
Contributor

szpak commented May 7, 2023

          Unrelated to the above but also related to Gradle 8 compatibility (at least with Gradle 8.1.1):

image

The repositories function is now clashing with Project.repositories from the Kotlin DSL. For now it seems to still compile, but it does show an error in the IDE. Doing something like the following fixes it (since thankfully the Project.repositories argument has a different name):

image

It might make sense to introduce an alias to repositories such as nexusRepositories and perhaps deprecate the former.

If I'm missing something obvious and there's a less hacky workaround please do let me know!

I tried going over the Gradle release notes to check if this change in behaviour is mentioned anywhere but couldn't find anything to reference. I'd appreciate if someone could find a reference as to why this is now happening.

Also, please let me know if you'd prefer that I create a new issue to track this.

Originally posted by @YarnSphere in #208 (comment)

@szpak
Copy link
Contributor Author

szpak commented May 7, 2023

@YarnSphere seems to find a workaround:


Regarding #208 (comment), where I say:

If I'm missing something obvious and there's a less hacky workaround please do let me know!

The less hacky workaround is simply:

nexusPublishing {
    this.repositories {
        sonatype()
    }
}

Which I find acceptable (I don't know how I originally missed this 😅).


I wonder if - in addition to mention it in the documentation - the plugin should do anything else (considering the backward compatibility)?

@TWiStErRob
Copy link
Collaborator

For now it seems to still compile, but it does show an error in the IDE.

This means the regression bug is in the IDE or the Gradle v IDEA integration. Is there a repro that we can use to report it to Gradle?

@Vampire
Copy link
Contributor

Vampire commented Jul 4, 2023

Seems to work just fine with Gradle 8.2 and IntelliJ IDEA 2023.1.3:
image

@Vampire
Copy link
Contributor

Vampire commented Jul 4, 2023

Actually even with 8.1 it works fine here.

@TWiStErRob

This comment was marked as outdated.

@Vampire
Copy link
Contributor

Vampire commented Jul 4, 2023

Wouldn't know why or how and there is no reproducer project attached here, is there?

@TWiStErRob

This comment was marked as off-topic.

@Vampire
Copy link
Contributor

Vampire commented Jul 4, 2023

Maybe Kotlin IntelliJ plugin version

@Vampire
Copy link
Contributor

Vampire commented Jul 4, 2023

231-1.8.21-IJ9161.38 here

@YarnSphere
Copy link

This example project showcased this issue, last I checked (at the time I wrote the comment this issue references): https://github.com/YarnSphere/nexus-publish-gradle-8

The IDE would complain without the this in the following line: https://github.com/YarnSphere/nexus-publish-gradle-8/blob/main/build.gradle.kts#L46

@Vampire
Copy link
Contributor

Vampire commented Jul 4, 2023

Interesting, with that it indeed happens

@YarnSphere
Copy link

YarnSphere commented Jul 4, 2023

Are you perhaps declaring your nexusPublishing configuration outside the scope of a Project (possibly outside of a build.gradle.kts)?

@Vampire
Copy link
Contributor

Vampire commented Jul 4, 2023

Yes and no, found the difference to mine.
I have it in a convention plugin, there it works perfectly fine.
If I move the block to the main build's build script, it happens the same in my project.

@Vampire
Copy link
Contributor

Vampire commented Jul 4, 2023

Btw. there is also this work-around:

nexusPublishing.repositories {
    sonatype()
}

@Vampire
Copy link
Contributor

Vampire commented Jul 4, 2023

Is this reported to somewhere already?
Seems like someone else should fix this. :-D

@YarnSphere
Copy link

YarnSphere commented Jul 4, 2023

I just took the error message as an implication that this is an intended consequence of the changes being made to the resolution algorithm, i.e. that this isn't a bug per se.

That's why I originally proposed the renaming/deprecation of the repositories function in this project. I am, however, sufficiently happy with either of the proposed work-arounds, since they're low friction enough (in fact, I prefer yours to mine 😃), provided there's a small reference to them in the documentation.

Do you believe this to be a bug that should be reported upstream? From the error message I assumed it's expected.

@Vampire
Copy link
Contributor

Vampire commented Jul 4, 2023

Actually, I interpreted the error message the other way around.
That IJ thinks it is currently resolved to the Project one and soon will be changed.

Also because I wonder why it should ever be the case, that it resolves to the extensions function fun Project.repositories while within nexusPublishing { ... } this is the NexusPublishingExtension which has a member fun repositories as direct members should always win. Especially as the extension function is not even for that this, but for an outer one, or actually for the delegate of the enclosing script instance.

And even if this resolution would "change soon", I don't think the IDE should display an error there for perfectly valid and working code, that is just non-sense and user unfriendly. So even if this is intended, it should imho be reported and change immediately by JetBrains.

Btw. another work-around variant, maybe even better:

nexusPublishing {
    repositories.sonatype()
}

@Vampire
Copy link
Contributor

Vampire commented Jul 4, 2023

Or another one:

import org.gradle.kotlin.dsl.repositories as builtInRepositories

builtInRepositories {
    mavenCentral()
}

nexusPublishing {
    repositories {
        sonatype()
    }
}

@marcphilipp
Copy link
Member

This is caused by an issue in IntelliJ idea: KTIJ-26463

@3flex
Copy link
Contributor

3flex commented Jan 13, 2024

KTIJ issue is fixed in 2023.3, can close?

@szpak
Copy link
Contributor Author

szpak commented Jan 13, 2024

@YarnSphere , as an original reported, is it fixed for you in IDEA 2023.3?

And thanks @3flex for the reminder :-).

@YarnSphere
Copy link

Seems fixed to me! Feel free to close! :)

TWiStErRob added a commit to TWiStErRob/junit-pioneer that referenced this issue Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants