Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a npm package as a maven dependency?

Tags:

npm

maven

I want to use a npm package in a java maven project.

It's just one file that is used in the java project.

We have two projects.

  1. react frontend project where a bundle.js is the artifact which is uploaded with maven

  2. java maven project where we use the bundle.js as a maven dependency

Now we want to get rid of the maven stuff in the react project.

So we will upload the bundle.js as a npm package into our npm registry.

We use nexus3 for our npm and maven repositories.

I want to avoid adding a maven plugin in the java project to install the npm package with a real npm installation.

Maybe there is kind of a npm maven proxy plugin for maven or a npm maven proxy possibility in nexus3?

Thank you!

like image 488
Martin Avatar asked Sep 18 '25 12:09

Martin


1 Answers

There is fresh maven plugin to do such operations like obtaining resources from NPM, filtering and packing into JAR:WAR: https://github.com/OrienteerBAP/JNPM

Sample for pom.xml

<plugin>
<groupId>org.orienteer.jnpm</groupId>
    <artifactId>jnpm-maven-plugin</artifactId>
    <version>1.0-SNAPSHOT</version>
    <executions>
        <execution>
            <goals>
                <goal>install</goal>
            </goals>
            <configuration>
                <packages>
                    <package>[email protected]</package>
                    <package>vuex@~3.4.0</package>
                </packages>
            </configuration>
        </execution>
    </executions>
</plugin>
like image 109
Ilya Naryzhnyy Avatar answered Sep 20 '25 06:09

Ilya Naryzhnyy