【问题标题】:Deploy third party jar as if it is a projects own built jar?将第三方 jar 部署为构建 jar 上的项目?
【发布时间】:2019-03-25 19:31:42
【问题描述】:

我必须使用公司专有的 jar 生成器来构建我需要发布到 maven 存储库的库。我的工作流程如下所示:

  1. 使用 jar 生成器生成 JAR 并将其导出到我的文件系统。将此 Jar 命名为 GenLib.jar
  2. 制作一个如下所示的项目: 外部项目 ExtProj/lib/Genlib.jar extproj/pom.xml
  3. 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.mycompany</groupId>
    	<artifactId>EXTProj</artifactId>
        <packaging>jar</packaging>
    	<build>
    		<plugins>
    			<plugin>
    				<groupId>org.apache.maven.plugins</groupId>
    				<artifactId>maven-install-plugin</artifactId>
    				<version>2.5.1</version>
    				<executions>
    					<execution>
    						<id>install-extlib</id>
    						<phase>install</phase>
    						<goals>
    							<goal>install-file</goal>
    						</goals>
    						<configuration>
    							<file>${project.basedir}/lib/EXTLib.jar</file>
    							<groupId>com.mycompany.EXTLib</groupId>
    							<artifactId>EXTLib</artifactId>
    							<version>1.0.0-SNAPSHOT</version>
    							<packaging>jar</packaging>
    						</configuration>
    					</execution>
    				</executions>
    			</plugin>
    		</plugins>
    	</build>
    </project>
  1. 我可以运行 mvn install 将文件安装到我的本地 maven 存储库。

但是,我还想运行 mvn deploy 将同一个 jar 部署到我的远程仓库。我怎么做?从我在 mavne deploy 插件中可以看到,这是不可能的。我可以使用 mvn deploy deploy-file,但每次部署时都需要我输入项目 artifactId、组 ID 等。我希望它使用 pom.xml 中的信息。理想情况下,远程仓库应包含 com.mycompany:EXTProj:1.0.0 或 com.mycompany:EXTLib:1.0.0。

【问题讨论】:

  • 您可以配置deploy-file,类似于install-file

标签: maven


【解决方案1】:

您可以配置部署插件以提供maven坐标(更多信息可以在这里找到https://maven.apache.org/plugins/maven-deploy-plugin/deploy-file-mojo.html)和pom本身中的文件名定义并调用它到安装阶段,maven配置文件应该有助于实现这个任务。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-04
    • 1970-01-01
    • 2015-04-30
    • 2011-05-08
    相关资源
    最近更新 更多