eirslett / frontend-maven-plugin

"Maven-node-grunt-gulp-npm-node-plugin to end all maven-node-grunt-gulp-npm-plugins." A Maven plugin that downloads/installs Node and NPM locally, runs NPM install, Grunt, Gulp and/or Karma.
Apache License 2.0
4.26k stars 870 forks source link

Problem using the plugin inside a Continuous Integration pipeline (Bitbucket pipeline) #873

Open trisquel87 opened 4 years ago

trisquel87 commented 4 years ago

Hello,

we have a problem using the plugin (v1.9.1 or any other) in Bitbucket pipelines.

We have this pipeline:

pipelines:
    default:
    - step:
          name: Package
          image: maven:3.5-jdk-8-alpine
          caches:
          - maven
          script:
          - mvn install -X
          - mvn clean package -P environment=production
          artifacts:
          - target/*.war

The error that we have is:

+ mvn install -X
Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T18:33:14Z)
Maven home: /usr/share/maven
Java version: 1.8.0_181, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-1.8-openjdk/jre 
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.19.78-coreos", arch: "amd64", family: "unix"
...
[DEBUG] Configuring mojo com.github.eirslett:frontend-maven-plugin:1.9.1:install-node-and-npm from plugin realm ClassRealm[plugin>com.github.eirslett:frontend-maven-plugin:1.9.1, parent: sun.misc.Launcher$AppClassLoader@70dea4e]
[DEBUG] Configuring mojo 'com.github.eirslett:frontend-maven-plugin:1.9.1:install-node-and-npm' with basic configurator -->
[DEBUG]   (f) installDirectory = /opt/atlassian/pipelines/agent/build/alert-web/target
[DEBUG]   (f) nodeDownloadRoot = https://nodejs.org/dist/
[DEBUG]   (f) nodeVersion = v10.9.0
[DEBUG]   (f) npmDownloadRoot = https://registry.npmjs.org/npm/-/
[DEBUG]   (f) npmVersion = provided
[DEBUG]   (f) project = MavenProject: es.company.alert:alert-web:1.0.0 @ /opt/atlassian/pipelines/agent/build/alert-web/pom.xml
[DEBUG]   (f) repositorySystemSession = org.eclipse.aether.DefaultRepositorySystemSession@63124c8b
[DEBUG]   (f) session = org.apache.maven.execution.MavenSession@d1d8e1a
[DEBUG]   (f) skipTests = false
[DEBUG]   (f) testFailureIgnore = false
[DEBUG]   (f) workingDirectory = /opt/atlassian/pipelines/agent/build/alert-web/src/main/resources/static/resources
[DEBUG]   (f) execution = com.github.eirslett:frontend-maven-plugin:1.9.1:install-node-and-npm {execution: install node and npm}
[DEBUG] -- end configuration --
[INFO] Installing node version v10.9.0
[DEBUG] Creating install directory /opt/atlassian/pipelines/agent/build/alert-web/target/node
[DEBUG] Creating temporary directory /opt/atlassian/pipelines/agent/build/alert-web/target/node/tmp
[INFO] Downloading https://nodejs.org/dist/v10.9.0/node-v10.9.0-linux-x64.tar.gz to /root/.m2/repository/com/github/eirslett/node/10.9.0/node-10.9.0-linux-x64.tar.gz
[INFO] No proxies configured
[INFO] No proxy was configured, downloading directly
[INFO] Unpacking /root/.m2/repository/com/github/eirslett/node/10.9.0/node-10.9.0-linux-x64.tar.gz into /opt/atlassian/pipelines/agent/build/alert-web/target/node/tmp
[INFO] Copying node binary from /opt/atlassian/pipelines/agent/build/alert-web/target/node/tmp/node-v10.9.0-linux-x64/bin/node to /opt/atlassian/pipelines/agent/build/alert-web/target/node/node
[INFO] Extracting NPM
[DEBUG] Deleting temporary directory /opt/atlassian/pipelines/agent/build/alert-web/target/node/tmp
[INFO] Installed node locally.
[INFO] 
[INFO] --- frontend-maven-plugin:1.9.1:npm (npm install) @ alert-web ---
[DEBUG] Configuring mojo com.github.eirslett:frontend-maven-plugin:1.9.1:npm from plugin realm ClassRealm[plugin>com.github.eirslett:frontend-maven-plugin:1.9.1, parent: sun.misc.Launcher$AppClassLoader@70dea4e]
[DEBUG] Configuring mojo 'com.github.eirslett:frontend-maven-plugin:1.9.1:npm' with basic configurator -->
[DEBUG]   (f) arguments = install --no-optional
[DEBUG]   (f) installDirectory = /opt/atlassian/pipelines/agent/build/alert-web/target
[DEBUG]   (f) npmInheritsProxyConfigFromMaven = true
[DEBUG]   (f) project = MavenProject: es.company.alert:alert-web:1.0.0 @ /opt/atlassian/pipelines/agent/build/alert-web/pom.xml
[DEBUG]   (f) repositorySystemSession = org.eclipse.aether.DefaultRepositorySystemSession@63124c8b
[DEBUG]   (f) session = org.apache.maven.execution.MavenSession@d1d8e1a
[DEBUG]   (f) skipTests = false
[DEBUG]   (f) testFailureIgnore = false
[DEBUG]   (f) workingDirectory = /opt/atlassian/pipelines/agent/build/alert-web/src/main/resources/static/resources
[DEBUG]   (f) execution = com.github.eirslett:frontend-maven-plugin:1.9.1:npm {execution: npm install}
[DEBUG] -- end configuration --
[INFO] Running 'npm install --no-optional' in /opt/atlassian/pipelines/agent/build/alert-web/src/main/resources/static/resources
[DEBUG] Executing command line [/opt/atlassian/pipelines/agent/build/alert-web/target/node/node, /opt/atlassian/pipelines/agent/build/alert-web/target/node/node_modules/npm/bin/npm-cli.js, install, --no-optional]
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] alert 1.0.0 ........................................ SUCCESS [  0.938 s]
[INFO] alert-util ......................................... SUCCESS [ 39.543 s]
[INFO] alert-business ...................................... SUCCESS [ 27.176 s]
[INFO] alert-web 1.0.0 .................................... FAILURE [  5.100 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:14 min
[INFO] Finished at: 2020-01-13T15:27:59Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.9.1:npm (npm install) on project alert-web: Failed to run task: 'npm install --no-optional' failed. 
java.io.IOException: Cannot run program "/opt/atlassian/pipelines/agent/build/alert-web/target/node/node" (in directory "/opt/atlassian/pipelines/agent/build/alert-web/src/main/resources/static/resources"): error=2, No such file or directory -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.9.1:npm (npm install) on project alert-web: Failed to run task
...
Caused by: org.apache.maven.plugin.MojoFailureException: Failed to run task
...
Caused by: com.github.eirslett.maven.plugins.frontend.lib.TaskRunnerException: 'npm install --no-optional' failed.
...
Caused by: com.github.eirslett.maven.plugins.frontend.lib.ProcessExecutionException: java.io.IOException: Cannot run program "/opt/atlassian/pipelines/agent/build/alert-web/target/node/node" (in directory "/opt/atlassian/pipelines/agent/build/alert-web/src/main/resources/static/resources"): error=2, No such file or directory
...
Caused by: java.io.IOException: Cannot run program "/opt/atlassian/pipelines/agent/build/alert-web/target/node/node" (in directory "/opt/atlassian/pipelines/agent/build/alert-web/src/main/resources/static/resources"): error=2, No such file or directory
...
Caused by: java.io.IOException: error=2, No such file or directory
...
[ERROR] 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :alert-web
Skipping cache upload for failed step`

The structure of our project is:

project |__alert-business |_pom.xml |__alert-util |_pom.xml |__alert-web |___pom.xml |__pom.xml

We have a react aplication with package.json inside one folder of alert-web subproject.

The aplication is compiling in local but not in the pipeline.

The pom.xml inside the alert-web subproject is:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <artifactId>alert-web</artifactId>
    <packaging>war</packaging>
    <name>alert-web</name>
    <description>....</description>
    <parent>
        <groupId>es.company.alert</groupId>
        <artifactId>alert</artifactId>
        <version>1.0.0</version>
    </parent>
<properties>
    <aspectj.version>1.8.10</aspectj.version>
    <node.version>v10.9.0</node.version>
    <frontend-maven-plugin>1.9.1</frontend-maven-plugin>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
    </dependency>
    <dependency>
        <groupId>es.company.alert</groupId>
        <artifactId>alert-util</artifactId>
        <version>1.0.0</version>
    </dependency>
    <dependency>
        <groupId>es.company.alert</groupId>
        <artifactId>alert-business</artifactId>
        <version>1.0.0</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.9.2</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.9.2</version>
    </dependency>
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-all</artifactId>
        <version>1.3</version>
        <scope>test</scope>
    </dependency>
</dependencies>
<profiles>
    <profile>
        <id>local</id>
        <properties>
            <activatedProperties>local</activatedProperties>
        </properties>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>com.github.eirslett</groupId>
                    <artifactId>frontend-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>npm run build</id>
                            <goals>
                                <goal>npm</goal>
                            </goals>
                            <phase>generate-resources</phase>
                            <configuration>
                                <arguments>run build:local --no-optional</arguments>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
    <profile>
        <id>develop</id>
        <properties>
            <activatedProperties>develop</activatedProperties>
        </properties>
        <build>
            <plugins>
                <plugin>
                    <groupId>com.github.eirslett</groupId>
                    <artifactId>frontend-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>npm run build</id>
                            <goals>
                                <goal>npm</goal>
                            </goals>
                            <phase>generate-resources</phase>
                            <configuration>
                                <arguments>run build:dev --no-optional</arguments>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
    <profile>
        <id>production</id>
        <properties>
            <activatedProperties>production</activatedProperties>
        </properties>
        <build>
            <plugins>
                <plugin>
                    <groupId>com.github.eirslett</groupId>
                    <artifactId>frontend-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>npm run build</id>
                            <goals>
                                <goal>npm</goal>
                            </goals>
                            <phase>generate-resources</phase>
                            <configuration>
                                <arguments>run build:production --no-optional</arguments>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>

</profiles>
<build>
    <!--
    <sourceDirectory>${project.build.directory}/generated-sources/delombok</sourceDirectory>
    -->
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
            <excludes>
                <exclude>**/node_modules/**</exclude>
                <exclude>**/react/**</exclude>
                <exclude>**/fonts/**</exclude>
            </excludes>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>false</filtering>
            <includes>
                <include>**/fonts/**</include>
            </includes>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <configuration>
                <nonFilteredFileExtensions>
                    <nonFilteredFileExtension>woff2</nonFilteredFileExtension>
                    <nonFilteredFileExtension>ttf</nonFilteredFileExtension>
                    <nonFilteredFileExtension>woff</nonFilteredFileExtension>
                    <nonFilteredFileExtension>svg</nonFilteredFileExtension>
                </nonFilteredFileExtensions>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <warName>alert</warName>
                <warSourceExcludes>node_modules/,react/</warSourceExcludes>
                <packagingExcludes>**/src/main/static/resources/node_modules/,**/src/main/static/resources/node/
                </packagingExcludes>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
            <groupId>com.github.eirslett</groupId>
            <artifactId>frontend-maven-plugin</artifactId>
            <version>1.9.1</version>
            <configuration>
                <nodeVersion>${node.version}</nodeVersion>
                <installDirectory>target</installDirectory>
                <workingDirectory>src/main/resources/static/resources</workingDirectory>
                <nodeDownloadRoot>https://nodejs.org/dist/</nodeDownloadRoot>
            </configuration>
            <executions>
                <execution>
                    <id>install node and npm</id>
                    <goals>
                        <goal>install-node-and-npm</goal>
                    </goals>
                    <phase>generate-resources</phase>
                </execution>
                <execution>
                    <id>npm install</id>
                    <goals>
                        <goal>npm</goal>
                    </goals>
                    <phase>generate-resources</phase>
                    <configuration>
                        <arguments>install --no-optional</arguments>
                        <installDirectory>target</installDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.7.9</version>
            <executions>
                <execution>
                    <id>default-prepare-agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <execution>
                    <id>default-report</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <trimStackTrace>false</trimStackTrace>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-clean-plugin</artifactId>
            <configuration>
                <filesets>
                    <fileset>
                        <directory>src/main/resources/static/resources/dist</directory>
                        <followSymlinks>false</followSymlinks>
                    </fileset>
                </filesets>
            </configuration>
        </plugin>
    </plugins>
    <finalName>alert</finalName>
</build>

`

We try to solve the error installing npm in the pipeline but we can't not compile the project. We also try to use others docker images for the pipeline but we have the same error.

Can you help us?

Thanks.

eirslett commented 4 years ago

Does it work when running locally?

trisquel87 commented 4 years ago

@eirslett yes, we don’t have any problem in local.

eirslett commented 4 years ago

Try setting <installDirectory> and <workingDirectory> for every execution maybe?

trisquel87 commented 4 years ago

Try setting <installDirectory> and <workingDirectory> for every execution maybe?

@eirslett I have the same problem.

eirslett commented 4 years ago

Is there any chance that the target directory is wiped out between executions, somehow? Or the node binary ends up in the wrong directory somehow? Try logging into the CI server/into the build pipeline and checking its filesystem?

KrKandula commented 4 years ago

I had a issue running the plugin, but it was because plugin requires maven 3.1 and above.

ghost commented 4 years ago

Normal npm/node releases won’t work on Alpine or any musl-libc based distribution. I had to abandon Alpine at work because this plugin is in many of our projects.

hyahyaoui commented 4 years ago

Hello I'm having the same issue with gitlab ci @hermitmaster what are you using instead of Alpine?

ghost commented 4 years ago

@hyahyaoui Debian slim based images. Really, anything with glibc works fine.

hyahyaoui commented 4 years ago

@hermitmaster thanks :)

breun commented 3 years ago

frontend-maven-plugin downloads a musl-based NodeJS since https://github.com/eirslett/frontend-maven-plugin/pull/853, so there should no longer be a need to install glibc (which adds quite a bit of disk usage to that otherwise tiny Alpine image, and I guess keeping it small is the point of using Alpine).