Maven中跳过Angular构建 | AI生成和翻译

Home 2025.09

简短回答:是的——你可以跳过 Angular/npm 构建,但不能使用像 --skip-web 这样的内置标志。请使用以下方法之一。

1) 在多模块构建中排除 Web 模块

如果你的 Angular 应用是独立的 Maven 模块(例如 web),只需在反应器中排除它:

mvn -pl '!web' -am clean package

或者仅构建后端模块:

mvn -pl :backend -am clean package

-am 会构建所需的依赖项;!web 语法会排除该模块。)

2) 添加“跳过前端”属性(适用于 frontend-maven-plugin 或 exec)

使用属性控制 npm 目标的执行,并通过命令行切换。

POM(web 模块或父级):

<properties>
  <skip.frontend>false</skip.frontend>
</properties>

<build>
  <plugins>
    <!-- 示例:com.github.eirslett:frontend-maven-plugin -->
    <plugin>
      <groupId>com.github.eirslett</groupId>
      <artifactId>frontend-maven-plugin</artifactId>
      <version>...你的版本...</version>
      <configuration>
        <skip>${skip.frontend}</skip>
      </configuration>
      <executions>
        <execution>
          <id>npm-build</id>
          <phase>prepare-package</phase>
          <goals>
            <goal>npm</goal>
          </goals>
          <configuration>
            <arguments>run build</arguments>
          </configuration>
        </execution>
      </executions>
    </plugin>

    <!-- 如果你使用 exec-maven-plugin 调用 npm -->
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>exec-maven-plugin</artifactId>
      <version>...你的版本...</version>
      <executions>
        <execution>
          <id>npm-build</id>
          <phase>prepare-package</phase>
          <goals><goal>exec</goal></goals>
          <configuration>
            <skip>${skip.frontend}</skip>
            <executable>npm</executable>
            <arguments>
              <argument>run</argument>
              <argument>build</argument>
            </arguments>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

命令行:

mvn -Dskip.frontend=true clean package

3) 使用 Maven 配置文件

将前端构建仅绑定到“with-frontend”配置文件中,并在开发中将“skip-frontend”配置文件设为默认。

POM:

<profiles>
  <profile>
    <id>with-frontend</id>
    <activation>
      <property>
        <name>!skip.frontend</name>
      </property>
    </activation>
    <build>
      <plugins>
        <!-- 同上方的插件配置,但不带 skip -->
      </plugins>
    </build>
  </profile>
</profiles>

命令行:


如果你确实需要构建 UI 时的加速技巧


总结

使用 -pl '!web' 排除 Web 模块,或者添加 skip.frontend 属性并配置你的插件执行以遵循它。虽然没有标准的 mvn package --skip-web,但上述两种模式是可靠且常见的。


Back

openai/gpt-5

Donate