将JAR安装到存储库时,Maven不会读取POM

时间:2014-10-08 14:03:25

标签: maven maven-3 pom.xml maven-install-plugin

我已按照指南here将JAR文件安装到我的本地存储库中。

我运行以下命令:

mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=log4j-weblayout-0.0.1-SNAPSHOT.jar

JAR文件是使用Maven构建的,其中包含一个列出其依赖项的POM文件。 JAR中的文件具有路径:

/META-INF/maven/in.ksharma/log4j-weblayout/pom.xml

Maven安装工件但不读取其POM。它会创建一个空的POM文件,该文件没有任何依赖项信息:

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>in.ksharma</groupId>
  <artifactId>log4j-weblayout</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <description>POM was created from install:install-file</description>
</project>

如何确保JAR中的POM是已安装的POM?

修改

JAR内各种文件的内容如下。

/META-INF/MANIFEST.MF

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By: kshitiz
Created-By: Apache Maven 3.1.0
Build-Jdk: 1.8.0

/META-INF/maven/in.ksharma/log4j-weblayout/pom.properties

#Generated by Maven
#Wed Oct 08 19:48:28 IST 2014
version=0.0.1-SNAPSHOT
groupId=in.ksharma
artifactId=log4j-weblayout

/META-INF/maven/in.ksharma/log4j-weblayout/pom.xml

<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>in.ksharma</groupId>
    <artifactId>log4j-weblayout</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <url>https://github.com/Kshitiz-Sharma/log4j-weblayout</url>
    <properties>
        <maven.compiler.source>1.6</maven.compiler.source>
        <maven.compiler.target>1.6</maven.compiler.target>
    </properties>
    <dependencies>
        <!-- Compile dependencies -->
        <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity</artifactId>
            <version>1.7</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>joor</artifactId>
            <version>0.9.3</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
            <scope>compile</scope>
        </dependency>

        <!-- Provided dependencies -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
            <scope>provided</scope>
        </dependency>

        <!-- Test dependencies -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>4.0.5.RELEASE</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>2.1.8</version>
            <scope>test</scope>
        </dependency>

    </dependencies>
</project>

3 个答案:

答案 0 :(得分:3)

我认为您需要从jar中提取pom.xml并使用pomFile property指定它,如下所示:

mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=log4j-weblayout-0.0.1-SNAPSHOT.jar -DpomFile=pom.xml

答案 1 :(得分:1)

似乎是already fixed bug(2015年1月), 虽然修复程序不在最新版本中(根据plugins official site在2014-08-27发布的版本2.5.2)

答案 2 :(得分:0)

似乎在3.0.0-M1版本的安装插件中已修复,但maven仍可能使用2.5.2作为默认值。您可以在pluginManagement部分中设置安装插件的版本:

  <pluginManagement>
      <plugins>
      ...
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-install-plugin</artifactId>
          <version>3.0.0-M1</version>
        </plugin>
      ...
      </plugins>
  </pluginManagement>

或在命令行上调用插件的正确版本:

mvn org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install-file -Dfile=log4j-weblayout-0.0.1-SNAPSHOT.jar
相关问题