【问题标题】:maven plug-ins specified in pom.xml don't executepom.xml 中指定的 maven 插件不执行
【发布时间】:2020-06-02 16:16:23
【问题描述】:

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

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

pom.xml 的一个 sn-p:

仅供参考,我没有包含所有依赖项和 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>

【问题讨论】:

    标签: java maven


    【解决方案1】:

    这两个插件都在&lt;pluginManagement&gt; 中定义。 pluginManagement 用于定义插件版本和配置。它不会将插件添加到生命周期中。您还需要在 &lt;plugins&gt; 中定义依赖插件(在 pluginManagement 之外)。

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

    【讨论】:

      【解决方案2】:

      我能够解决这个问题。我从节下删除了插件。此外,对于 jar 插件,我删除了 和 节。移除这些之后,jar 被正确创建,并且清单文件被正确生成。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-01-17
        • 2011-03-06
        • 2014-07-27
        • 1970-01-01
        • 1970-01-01
        • 2014-10-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多