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

Add FAQ/usage entry about dependencyResolutionManagement together with gradle-node-plugin #134

Closed
dawi opened this issue Jan 11, 2021 · 16 comments
Milestone

Comments

@dawi
Copy link

dawi commented Jan 11, 2021

Gradle 6.8 introduces the "Central declaration of repositories".

https://docs.gradle.org/6.8/release-notes.html#central-declaration-of-repositories

If I use this new feature in our project together with the gradle-node-plugin, some Java libraries cannot be resolved.

To track down the issue, I have added the flag FAIL_ON_PROJECT_REPOS to the configuration:

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        maven("https://some-internal-nexus/repository/repo/")
    }
}

This shows the cause of the issue:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':wicket-components:nodeSetup'.
> Build was configured to prefer settings repositories over project repositories but repository 'ivy' was added by unknown code

It seems that an Ivy repository is added to the project which seems to be the cause of the issue.

@deepy
Copy link
Member

deepy commented Jan 11, 2021

If you set distBaseUrl to null it should work, but you'll have to add the IvyRepository yourself if you want to be able to use download = true

But I don't think your initial issue is related to this, the IvyRepository only contains node executables.

@deepy
Copy link
Member

deepy commented Jan 12, 2021

I suspect what you really want is RepositoriesMode.PREFER_SETTINGS

@dawi
Copy link
Author

dawi commented Jan 12, 2021

It seems so at first glance, but RepositoriesMode.PREFER_SETTINGS will cause the IvyRepository to be ignored.

/**
 * If this mode is set, any repository declared directly in a project,
 * either directly or via a plugin, will be ignored.
 */
PREFER_SETTINGS,

I think I will open a gradle ticket also. In the current state, I cannot use the centralized repository declartion.
Because I still have to declare the repository at the project level, because otherwise the IvyRepository is ignored.

It would be great if gradle had an option that would behave exactly as if the repository was defined at project level.

@deepy
Copy link
Member

deepy commented Jan 12, 2021

Well you could create the IvyRepository yourself in the centralised location, though you might not want to add it to all projects.
Alternately maybe you can make the node build an includedBuild and let that have a different configuration?

@dawi
Copy link
Author

dawi commented Jan 12, 2021

Yes, but all those things are just workarounds in my opinion.

For now I will continue to declare the repository via allprojects (so also in one place).
I just liked the idea, to move repository configuration from build to settings. Sadly it didn't work out.

gradle/gradle#15754

bsautel added a commit that referenced this issue Jan 18, 2021
…management policy in a test. For now, it specifies the PREFER_PROJECT policy, which seems to be equivalent to the former behavior.

We also would like the plugin to work with the PREFER_SETTINGS policy but it currently does not. It will maybe change thanks to issue gradle/gradle#15754.
@bsautel
Copy link
Contributor

bsautel commented Jan 18, 2021

I added a dependency resolution management policy to an integration test.

It obviously fails with FAIL_ON_PROJECT_REPOS, that's logical. But I confirm it also fails with PREFER_SETTINGS.

For now, the test uses PREFER_PROJECT which seems to correspond to the former behavior. I'll adjust if anything changes thanks to gradle/gradle#15754. The issue has been added to the 6.8.1 milestone, so we can expect some news soon.

bsautel added a commit that referenced this issue Jan 18, 2021
…management policy in a test. For now, it specifies the PREFER_PROJECT policy, which seems to be equivalent to the former behavior.

We also would like the plugin to work with the PREFER_SETTINGS policy but it currently does not. It will maybe change thanks to issue gradle/gradle#15754.
@deepy deepy added this to the 3.0 milestone Jan 20, 2021
@deepy
Copy link
Member

deepy commented Jan 20, 2021

The solution to your problem @dawi is in this comment: gradle/gradle#15754 (comment)
Adding an IvyRepository with content specification manually, set distBaseUrl to null

I'm repurposing this issue to document how to do this.

@deepy deepy changed the title Can't use Gradle 6.8 dependencyResolutionManagement together with gradle-node-plugin Add FAQ/usage entry about dependencyResolutionManagement together with gradle-node-plugin Jan 20, 2021
@deepy
Copy link
Member

deepy commented Jan 20, 2021

There's a brief integration test that proves that this works, I'll extract that into documentation tomorrow-ish

bsautel added a commit that referenced this issue Feb 3, 2021
…tories declaration is enabled. Add a test to ensure that the plugin works by default when the centralized repositories declaration is enabled and it does not need to download the Node.js bundle.
@bsautel
Copy link
Contributor

bsautel commented Feb 3, 2021

I added a section in the FAQ explaining how to use the plugin when using the centralized repositories declaration.

I also added a test to ensure that the plugin works by default when using the centralized repositories declaration and download = false.

Please let me know if you have any feedback. Otherwise I think we can close the issue.

@dawi
Copy link
Author

dawi commented Feb 4, 2021

@bsautel I've already configured it in the same way you documented and it works well.

Maybe a few suggestions regarding the documentation:

  • It seems that the code is Kotlin DSL, therefore the headlines should be build.gradle.kts and settings.gradle.kts.
  • I am note sure, but I think ivy("v[revision]/ivy.xml") does not need to be configured.
  • Instead of setUrl("https://nodejs.org/dist/") it could be url = "https://nodejs.org/dist/" to be consistent with name = "Node.js"

@bsautel
Copy link
Contributor

bsautel commented Feb 4, 2021

Thanks @dawi for your feedback! I fixed that. And I confirm this uses the Groovy DSL.

@deepy
Copy link
Member

deepy commented Feb 6, 2021

The reason for setUrl() was for kotlin compatibility, while this works in groovy in kotlin it gives a Type mismatch as getUrl() returns an URI

@deepy
Copy link
Member

deepy commented Feb 6, 2021

And before anyone thinks "Aha! That makes sense, but we should switch to the setter for name as well!" if you do that, IntelliJ will helpfully tell you that you should use the property access syntax instead 😈

deepy added a commit that referenced this issue Feb 6, 2021
@deepy
Copy link
Member

deepy commented Feb 6, 2021

I've removed the ivy() call from the plugin itself as well, pushed it to run the tests, and reverted the change in the documentation to make it kotlin copy-paste friendly

@deepy deepy closed this as completed Feb 6, 2021
deepy added a commit that referenced this issue Feb 6, 2021
url = "foo" doesn't work in kotlin, so while this doesn't
look that great, it does work in both languages.
@bsautel
Copy link
Contributor

bsautel commented Feb 7, 2021

Ok, perfect! Thanks!

@dawi
Copy link
Author

dawi commented Feb 9, 2021

Just in case someone want's to set distBaseUrl to null via Kotlin DSL, here is how:

configure<NodeExtension> {
    distBaseUrl.set(null as String?) // to prevent IvyRepository to be created via NodePlugin
}

@bsautel maybe also something for the faq

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