Issue
my maven project has the following structure:
- "base" module -- contains shared java files -- should contain shared javascript files
- module 1 -- use shared java files as maven dependency -- should use shared javascript files using ?
- module 2 -- use shared java files as maven dependency -- should use shared javascript files using ?
Currently, webpack seems to be the new thing in javascript packaging and npm seems to be a proper package manager. So i tried the following: - base modules creates a npm bundle (with npm pack) using webpack - modules 1 and 2 install this bundle manually using a relative path to the base module target folder where the npm package is
Why didn't i use npm publish? - Its not possible to update published npm packages, so every build would need to create a new version number - It would need an internet connection to build
Other options? - I thought about using the maven resources plugin, but this seems to be a lot of manual work included (file names, folders, etc.)
So what I'm asking for is: Do you share javascript code between maven modules within the same project? How do you achieve that? There has to be a better way to do that, or?
If you want to look at my project, take a look here: https://github.com/stefanrinderle/softvis3d
Thanks in advance for your answers an comments!
Solution
Basically to redistribute npm modules separately you should use npm publish
. During dev time, though, npm has nice feature npm link
, that links your local folder as global dependency and makes npm use it instead of downloading from repository. So, I've just added npm link
to your project and changed node installation directory so all submodules use the same node instance. This way you can develop your modules easily and publish whenever you're ready.
base/pom.xml:
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
...
<configuration>
...
<installDirectory>../node</installDirectory>
</configuration>
<executions>
<execution>
<id>npm link</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>link</arguments>
</configuration>
</execution>
</executions>
</plugin>
..module/pom.xml
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<configuration>
<installDirectory>../node</installDirectory>
</configuration>
<executions>
<execution>
<!-- link before install -->
<id>npm link softvis3d-viewer</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>link softvis3d-viewer</arguments>
</configuration>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
</execution>
...
</executions>
</plugin>
..module/package.json
"devDependencies": {
...
"softvis3d-viewer": "0.0.4-SNAPSHOT"
},
Answered By - Dzmitry Paulenka
Answer Checked By - Willingham (JavaFixing Volunteer)