node-gradle / gradle-node-plugin

Gradle plugin for integrating NodeJS in your build. :rocket:
Apache License 2.0
599 stars 117 forks source link

Cannot use Java dependencies in the same module as com.github.node-gradle.node plugin #268

Closed sergeykad closed 1 year ago

sergeykad commented 1 year ago

The com.github.node-gradle.node plugin overrides configured repositories which makes downloading Java artifacts fail. For example, the following configuration returns an error.

plugins {
    id 'com.github.node-gradle.node' version '3.5.1'
    id 'java'
}

node {
    download = true
}

dependencies {
    implementation 'org.javatuples:javatuples:1.2'
}
Execution failed for task ':mytask:build'.
> Could not resolve all dependencies for configuration ':mytask:runtimeClasspath'.
  The project declares repositories, effectively ignoring the repositories you have declared in the settings.
  You can figure out how project repositories are declared by configuring your build to fail on project repositories.
  See https://docs.gradle.org/8.0.1/userguide/declaring_repositories.html#sub:fail_build_on_project_repositories for details.
   > Could not find org.javatuples:javatuples:1.2.
     Required by:
         project :mytask

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
deepy commented 1 year ago

If you're using FAIL_ON_PROJECT_REPOS you need to configure the repository yourself (as there's no way for the plugin to do this for you), please see https://github.com/node-gradle/gradle-node-plugin/blob/master/docs/faq.md#is-this-plugin-compatible-with-centralized-repositories-declaration for the instructions

sergeykad commented 1 year ago

My issue seems to be a bit different according to the Gradle error message. I do have centralized repositories declaration, but I do not set RepositoriesMode and it uses the default value. What I think is happening is that the repository configured by the plugin overrides all repositories from the centralized declaration and as a result, Gradle does not have any repository to download Java artifacts from. In any case, the same solution works.

deepy commented 1 year ago

Yeah that's the PREFER_PROJECT functionality, with that it'll use the centralized settings unless you have project configuration and plugins like this will effectively override the repositories. But if you do have centralized repositories I highly recommend using FAIL_ON_PROJECT_REPOS, it will highlight these issues in the more expected way