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

Resolve rewrite dependencies from -Pmoderne.gradle.classpath if provided #259

Closed

Conversation

timtebeek
Copy link
Contributor

What's changed?

If the gradle project has no repositories defined, then resolve released Rewrite dependencies from Maven Central, and snapshots from Sonatype OSS>

What's your motivation?

Up to now we had been failing with

ModuleVersionNotFoundException: Cannot resolve external dependency org.openrewrite:rewrite-core:8.11.5 because no repositories are defined.

@timtebeek timtebeek added the bug Something isn't working label Jan 8, 2024
@timtebeek timtebeek requested a review from shanman190 January 8, 2024 18:14
@timtebeek timtebeek self-assigned this Jan 8, 2024
@timtebeek
Copy link
Contributor Author

Adding note here as I'm stepping away for dinner

This might work. Though it may be better done as an afterEvaluate in the plugin class itself as I'm not sure this will be allowed in all versions (ie. Modifying the repositories during the execution phase). The other facet is that configuration cache disallows access to the project within tasks, so this would result in drifting further away from being able to support that feature (this isn't to say that there isn't a lot of existing work necessary to get to a point where it can be supported in the first place).

@timtebeek timtebeek marked this pull request as ready for review January 8, 2024 18:41
@timtebeek timtebeek changed the title Resolve rewrite dependencies from default repositories if none are defined Resolve rewrite dependencies from mavenLocal if no repositories are defined Jan 9, 2024
@timtebeek
Copy link
Contributor Author

Peter shared some insights that we're likely applying the plugin to unsuitable root projects, whereas we might instead need to apply to projects that use the Java or Kotlin plugin, as those are more likely to have repositories configured. Did I summarize that correctly @pstreef ?

@pstreef
Copy link
Contributor

pstreef commented Jan 9, 2024

The problem is that gradle projects are not guaranteed to have repositories defined (there is no default and not every project is actually a project with code in it).
We assume that the rootProject does have the right configuration for us to add dependencies to. Which is not always the case. And even if it does it might not have the repositories configured.

We can reproduce this issue on moderne-cli using:

export MODERNE_GRADLE_PLUGIN=io.moderne:modgradle:2.0.5; ./gradlew moderneLst --init-script=./mod/src/main/resources/init-mod.gradle -Pmoderne.lstOutputDirectory=/tmp/lstout

and we can make this work (at least further than this issue) by adding the convention plugin to the root project:

plugins{
    ...
    id("moderne-cli.java-conventions")
}

@timtebeek timtebeek marked this pull request as draft January 9, 2024 11:39
@timtebeek
Copy link
Contributor Author

So as indicated: this is likely to improve things for folks that use gradle projects that set repositories through plugins or not in the root project at all; as it stands right now it will also break for folks using DependencyResolutionManagement, which is why we haven't merged yet.

@timtebeek timtebeek changed the title Resolve rewrite dependencies from mavenLocal if no repositories are defined Resolve rewrite dependencies from -Pmoderne.gradle.classpath if provided Jan 11, 2024
@timtebeek
Copy link
Contributor Author

We've opted for an alternative that does not require further changes in the plugin beyond 55a2219...878e4a6

@timtebeek timtebeek closed this Jan 12, 2024
@timtebeek timtebeek deleted the resolve-rewrite-dependencies-from-default-repositories branch January 12, 2024 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants