java - pom.xml 中指定的 maven 插件不执行

标签 java maven

我正在构建我的 Java 项目,并指定了 2 个 maven 插件:maven-jar-plugin 和 maven-dependency-plugin。我从命令行执行 mvn clean package 。源代码编译成功;但是,我从未看到依赖插件执行。此外,在执行 mvn --debug clean package 时,我没有看到 jar-plugin 使用我指定的参数执行。

我正在寻求一些帮助,以了解为什么在执行 mvn clean package 时这些插件没有运行。

pom.xml 的片段:

仅供引用,我没有包含所有依赖项和 groupId,主类信息已更改以保护无辜者。但是,pom.xml 的结构是完整的。

`<?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>

  <groupId>com.mygroupId</groupId>
  <artifactId>ssmgr</artifactId>
  <version>0.1</version>

  <name>ssmgr</name>


  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <mainClass>com.myclass.App</mainClass>
    <dependenciesDirectory>libs</dependenciesDirectory>
  </properties>

  <build>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-dependency-plugin</artifactId>
          <version>3.1.1</version>
          <executions>
            <execution>
              <id>copy-dependencies</id>
              <phase>package</phase>
              <goals>
                <goal>copy-dependencies</goal>
              </goals>
              <configuration>
                <outputDirectory>${project.build.directory}/${dependenciesDirectory}</outputDirectory>
                <overWriteReleases>false</overWriteReleases>
                <overWriteSnapshots>false</overWriteSnapshots>
                <overWriteIfNewer>true</overWriteIfNewer>
                <!-- <overWriteIfNewer>true</overWriteIfNewer> -->
                <!--<includeScope>runtime</includeScope>
                <excludeScope>test</excludeScope>
                <useBaseVersion>false</useBaseVersion> -->
              </configuration>
            </execution>
          </executions>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-jar-plugin</artifactId>
          <version>3.2.0</version>
          <executions>
            <execution>
              <id>create-jar</id>
              <configuration>
                <archive>
                  <manifest>
                    <addClasspath>true</addClasspath>
                    <classpathPrefix>${dependenciesDirectory}</classpathPrefix>
                    <mainClass>com.myclass.App</mainClass>
                  </manifest>
                </archive>
              </configuration>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
  <dependencies>
    <dependency>
    </dependency>
  </dependencies>
</project>

最佳答案

这两个插件均在 <pluginManagement> 中定义。 。 pluginManagement 用于定义插件版本和配置。它不会将插件添加到生命周期中。您需要在 <plugins> 中定义依赖插件以及(在插件管理之外)。

Maven Jar 插件实际上隐式包含在生命周期中,但由于您不配置插件本身而是插件的执行,因此这些值永远不会产生任何影响。

关于java - pom.xml 中指定的 maven 插件不执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60284348/

相关文章:

java - 在 Spring 请求中验证枚举

java - Java中的可变 boolean 字段

maven - spring-swagger-wordnik-client 项目的分发管理中缺少站点信息

maven - 使用 Maven 在 Azure DevOps 中构建多模块项目的 Jacoco 代码覆盖率问题

java - 使用 Nexus3 模拟阶段存储库

Java 或 Scala maven 使用 CLASSPATH 安装 jar

java - 检查我的代码,我使用 ThreadLocal 来管理 HttpSession

java - Hibernate 循环引用

java - 将 Hibernate 与动态 Eclipse 插件一起使用

java - 多模块 Spring Boot 配置