frontend-maven-plugin 运行s npm 运行 build 找不到 package.json 文件

frontend-maven-plugin when it runs npm run build can't find package.json file

我正在构建一个带有 spring 引导后端和 angular 前端的应用程序。 运行ning maven 时,我正在使用 frontend-maven-plugin 构建前端 当我 运行 mvn spring-boot:运行 我得到这个错误:

mvn spring-boot:run
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------< com.demo:investmentswallet >------------------
[INFO] Building investmentswallet 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:2.2.6.RELEASE:run (default-cli) > test-compile @ investmentswallet >>>
[INFO]
[INFO] --- frontend-maven-plugin:1.9.1:install-node-and-npm (install-npm) @ investmentswallet ---
[INFO] Node v12.16.3 is already installed.
[INFO]
[INFO] --- frontend-maven-plugin:1.9.1:npm (npm-install) @ investmentswallet ---
[INFO] Running 'npm install' in C:\Users\Michal\Desktop\InvestmentsWallet
[INFO] npm WARN saveError ENOENT: no such file or directory, open 'C:\Users\Michal\package.json'
[INFO] npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\Michal\package.json'
[INFO] npm WARN @auth0/angular-jwt@2.0.0 requires a peer of @angular/common@^6.0.0 but none is installed. You must install peer dependencies yourself.
[INFO] npm WARN gatsby-plugin-react-helmet@3.1.7 requires a peer of gatsby@^2.0.0 but none is installed. You must install peer dependencies yourself.
[INFO] npm WARN react-helmet@5.2.1 requires a peer of react@>=15.0.0 but none is installed. You must install peer dependencies yourself.
[INFO] npm WARN react-side-effect@1.2.0 requires a peer of react@^0.13.0 || ^0.14.0 || ^15.0.0 || ^16.0.0 but none is installed. You must install peer dependencies yourself.
[INFO] npm WARN Michal No description
[INFO] npm WARN Michal No repository field.
[INFO] npm WARN Michal No README data
[INFO] npm WARN Michal No license field.
[INFO]
[INFO] audited 73 packages in 0.853s
[INFO] found 1 low severity vulnerability
[INFO]   run `npm audit fix` to fix them, or `npm audit` for details
[INFO]
[INFO] --- frontend-maven-plugin:1.9.1:npm (npm run build) @ investmentswallet ---
[INFO] Running 'npm run build' in C:\Users\Michal\Desktop\InvestmentsWallet
[INFO] npm ERR! code ENOENT
[INFO] npm ERR! syscall open
[INFO] npm ERR! path C:\Users\Michal\package.json
[INFO] npm ERR! errno -4058
[INFO] npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\Michal\package.json'
[INFO] npm ERR! enoent This is related to npm not being able to find a file.
[INFO] npm ERR! enoent
[INFO]
[INFO] npm ERR! A complete log of this run can be found in:
[INFO] npm ERR!     C:\Users\Michal\AppData\Roaming\npm-cache\_logs20-05-24T13_11_03_257Z-debug.log
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.802 s
[INFO] Finished at: 2020-05-24T15:11:03+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.9.1:npm (npm run build) on project investmentswallet: Failed to run task: 'npm run build' failed. org.apache.commons.exec.ExecuteException: Process exited with an error: -4058 (Exit value: -
4058) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[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

好像找不到package.json文件? 为什么它在用户目录中寻找它? 它在客户端文件夹中

这是我的 pom:

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.demo</groupId>
    <artifactId>investmentswallet</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>investmentswallet</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>5.3.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>com.github.eirslett</groupId>
                <artifactId>frontend-maven-plugin</artifactId>
                <version>1.9.1</version>
                <configuration>
                    <nodeVersion>v12.16.3</nodeVersion>
                </configuration>
                <executions>
                    <execution>
                        <id>install-npm</id>
                        <goals>
                            <goal>install-node-and-npm</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>npm-install</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>npm run build</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <configuration>
                            <arguments>run build</arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>target/classes/public</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>client/dist/client</directory>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

这是我的项目结构:

知道发生了什么事吗?

好的,我发现解决这个问题的方法是在 frontend-maven-plugin 配置中你必须指定 workingDirectory 和 installDirectory。所以在我的例子中,pom.xml 中的插件定义将如下所示:

<plugin>
                <groupId>com.github.eirslett</groupId>
                <artifactId>frontend-maven-plugin</artifactId>
                <version>1.9.1</version>
                <configuration>
                    <nodeVersion>v12.16.3</nodeVersion>
                    <workingDirectory>client</workingDirectory>
                    <installDirectory>target</installDirectory>
                </configuration>
                <executions>
                    <execution>
                        <id>install-npm</id>
                        <goals>
                            <goal>install-node-and-npm</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>npm-install</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>npm run build</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <configuration>
                            <arguments>run build</arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>