当我将打包设置为捆绑时,Maven 项目中的 PluginVersionResolutionException
PluginVersionResolutionException in Maven project when I set packaging to bundle
在我的 Maven 项目中,当我将打包类型从 'jar' 更改为 'bundle' 时,我的大部分插件(编译器、部署、安装、资源、surefire)都丢失了它们的版本。为什么是这样?
我的pom.xml如下:
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.ui_4.4.35_patch</artifactId>
<version>1.0.0</version>
<packaging>bundle</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>4.2.1</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${project.artifactId}</Bundle-Name>
<Export-Package>web.admin.*</Export-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
有两种可能的方法。我在自己的项目中使用的是保留 bundle
打包并将 Maven 插件版本添加到 pom.xml 中的 pluginManagement
部分。例如:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
<!-- Add you current 'plugins' section here. -->
</build>
除了版本,还可以给每个插件加上configuration
。如果你的项目有一个父 pom,那么很自然地在那里添加 pluginManagement
部分而不是在你的 bundle 模块中。
或者,正如@khmarbaise 所建议的,您可以使用 jar
打包并仅使用 maven-bundle-plugin 生成清单。 plugin documentation page.
中描述了该方法
在我的 Maven 项目中,当我将打包类型从 'jar' 更改为 'bundle' 时,我的大部分插件(编译器、部署、安装、资源、surefire)都丢失了它们的版本。为什么是这样?
我的pom.xml如下:
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.ui_4.4.35_patch</artifactId>
<version>1.0.0</version>
<packaging>bundle</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>4.2.1</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${project.artifactId}</Bundle-Name>
<Export-Package>web.admin.*</Export-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
有两种可能的方法。我在自己的项目中使用的是保留 bundle
打包并将 Maven 插件版本添加到 pom.xml 中的 pluginManagement
部分。例如:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
<!-- Add you current 'plugins' section here. -->
</build>
除了版本,还可以给每个插件加上configuration
。如果你的项目有一个父 pom,那么很自然地在那里添加 pluginManagement
部分而不是在你的 bundle 模块中。
或者,正如@khmarbaise 所建议的,您可以使用 jar
打包并仅使用 maven-bundle-plugin 生成清单。 plugin documentation page.