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 Project Dependency Configuration #71

Open
myronu opened this issue Feb 24, 2020 · 6 comments
Open

Add Project Dependency Configuration #71

myronu opened this issue Feb 24, 2020 · 6 comments

Comments

@myronu
Copy link

myronu commented Feb 24, 2020

I'm trying to set up a multi-project Gradle build. We have a node (Angular) library, several Angular projects that depend on the library, and Spring Boot (Java) projects that will contain the final output. There are examples on the web for how to set up the node vs Java projects so that the node projects build first and their output is included in the WAR produced by the Java projects so that was pretty simple.

However, because the node plugin doesn't appear to declare any outputs or configurations, I am having problems getting node projects to depend on each other or the library. The Java plugin declares dependency configurations like readOnly, implementation, etc. If this plugin declares anything like that, I cannot figure out what it is.

Is there a way to make one node project depend on another node project?

@deepy
Copy link
Member

deepy commented Feb 24, 2020

Where I work we use npm run dist to build our application, so we've got a npmRunDist task we depend on

@deepy
Copy link
Member

deepy commented Feb 25, 2020

So this plugin provides an easy way to work with npm/yarn/etc, it doesn't build things itself like the java plugin does.
I'm not actually certain how you'd accomplish what you want with npm, but what I can find suggest the following:
Either use a file: link in your dependencies, or:
Start by building the dependency, npm install it.
Run npm link ../../path/to/your/dep

@myronu
Copy link
Author

myronu commented Feb 25, 2020

I was able to use gradle configurations to set up the proper dependencies to work around this. It works like this:

  1. Declare a configuration in your base script
configurations {
    npmResources {
      canBeResolved = true
      canBeConsumed = true
    }
  1. Make the library build depend on the folder containing its build output (note libBuildDir is not a standard variable, but one I defined):
dependencies {
  npmResources fileTree("${libBuildDir}/") {
    builtBy 'buildLib'
  }
}
  1. Make your client project depend on the output of the lib project:
dependencies {
  npmResources project(path: ':projects:my-library', configuration: 'npmResources')
}
  1. Make npmInstall depend on the lib project:
npmInstall.dependsOn(configurations.npmResources)

@bsautel
Copy link
Contributor

bsautel commented Feb 26, 2020

Personnally, I use a different approach to do that. I make a jar including the webapp in its resources and I add an implementation dependency to this jar to get this in the global application build.

Your suggestion seems to be more elegant than mine, but there is something I don't understand (I don't know very well how the Gradle configurations work). Is the npmResources configuration automatically embedded in the global application jar or war or do you have to add anything to get it done?

@myronu
Copy link
Author

myronu commented Mar 2, 2020

I don't think any plugin defines npmResources. You can declare configurations on the fly, which is what I'm doing. Adding the dependency in the way I did it lets the downstream project depend on it and include it. In my WAR task I was able to do something like this to get the Node output into my WAR where Spring Boot could find it:

from (configurations.npmResources) { into 'WEB-INF/classes/static' }

Please note that I actually used a different configuration that depended on the output of npm_run_build since npmResources was used for my library project, but it works the same.

@bsautel
Copy link
Contributor

bsautel commented Mar 5, 2020

Ok, thank you! Now I understand how you proceed and that's very elegant!

I read again your original question and as far as I understand, your problem with this configuration is that when you build the main Spring Boot application, it does not automatically trigger a build of the web 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

No branches or pull requests

3 participants