還是自己學藝不精,沒空系統學習,也是邊用邊學,這裏記錄下。
感謝博主的文章:https://www.cnblogs.com/wxyidea/p/10276672.html
先說結論:
原因出在在
<build>
下使用pluginManagement配置plugins和直接配置plugins是不同的。
形如:
<build>
<finalName>iot-kafkamsg</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>cn.wxyidea.KafkaMsgDemo</mainClass>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
而直接使用plugins:
<build>
<finalName>Dr</finalName>
<plugins>
<!-- 可執行jar 插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.fulong.drs.controller.PressureTest</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
區別是
- pluginManagement是一種在項目的多個模塊中共享相同插件配置的方法, 它旨在配置可以被其它模塊繼承的插件信息,即是對插件的聲明,在pluginManagement中配置plugins,執行maven命令時,不會被maven加載。
pluginManagement中聲明的插件可以被當前pom或子pom中引用,比如你在項目的父pom中使用pluginManagement聲明插件,那麼在子pom中可以繼承該插件,只需要在plugins節點中配置 groupId 和 artifactId就可以完成插件的引用。- plugins纔是插件的實際調用,它可以自己定義plugin,也可以從父pom的pluginManagement中繼承。
ok了。
順便記錄下自己排查插件沒有生效的方法:就是看maven運行命令時的日誌,如圖所示: