【问题标题】:Missing aar file in maven2 multi-project buildmaven2 多项目构建中缺少 aar 文件
【发布时间】:2010-09-09 13:33:32
【问题描述】:

我正在尝试使用 maven2 来构建一个 axis2 项目。我的项目被配置为带有 AAR、WAR 和 EAR 模块的父项目。当我运行父项目的包目标时,控制台显示成功构建并创建了所有文件。但是,AAR 项目生成的 AAR 文件不包含在生成的 WAR 项目中。 AAR 项目被列为 WAR 项目的依赖项。当我显式运行 WAR 的包目标时,AAR 文件将包含在 WAR 文件中。

为什么父级的包目标在运行子级的包目标时不包含必要的依赖关系?

我在我的战争项目中使用 maven-war-plugin v2.1-alpha-2。

父 POM:

<parent>
    <groupId>companyId</groupId>
    <artifactId>build</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.nationwide.nf</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>1.0.0-SNAPSHOT</version>
<modules>
    <module>ws-war</module>
    <module>ws-aar</module>
    <module>ws-ear</module>
</modules>

AAR POM:

<parent>
    <artifactId>parent</artifactId>
    <groupId>companyId</groupId>
    <version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>companyId</groupId>
<artifactId>ws-aar</artifactId>
<version>1.0.0-SNAPSHOT</version>
<description/>
<packaging>aar</packaging>
<dependencies>...</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.5</source>
                <target>1.5</target>
            </configuration>
        </plugin> 

        <plugin>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-wsdl2code-maven-plugin</artifactId>
            <version>1.4</version>
            <configuration>...</configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>wsdl2code</goal>
                    </goals>
                    <id>axis2-gen-sources</id>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-aar-maven-plugin</artifactId>
            <version>1.4</version>
            <extensions>true</extensions>
            <configuration>...</configuration>
        </plugin>
    </plugins>
</build>

战争 POM:

<parent>
    <artifactId>parent</artifactId>
    <groupId>companyId</groupId>
    <version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>companyId</groupId>
<artifactId>ws-war</artifactId>
<packaging>war</packaging>
<version>1.0.0-SNAPSHOT</version>
<description/>
<dependencies>
    <dependency>
        <groupId>companyId</groupId>
        <artifactId>ws-aar</artifactId>
        <type>aar</type>
        <version>1.0.0-SNAPSHOT</version>
    </dependency>
    .
    .
    .
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1-alpha-2</version>
            <configuration>
                <warName>appName</warName>
            </configuration>
        </plugin>
    </plugins>
</build>

谢谢, 乔

【问题讨论】:

    标签: maven-2


    【解决方案1】:

    通过将以下插件添加到 ws-war pom 文件中,我能够让我的 maven 构建正常工作:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>
                                ${project.build.directory}/${project.build.finalName}/WEB-INF/services
                            </outputDirectory>
                            <includeArtifactIds>
                                ws-aar
                            </includeArtifactIds>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
    

    【讨论】:

    • 这太糟糕了,你不得不求助于依赖插件,但我很高兴你让它工作。我认为这可能是战争插件中的一个错误,你可能想在 Maven 用户组上发帖,看看那里是否有人可以帮助你。
    【解决方案2】:

    您是否尝试过在依赖项中使用“type”元素?例如:

    <dependency>
      <groupId>group-a</groupId>
      <artifactId>artifact-b</artifactId>
      <version>1.0</version>
      <type>aar</type>
    </dependency>
    

    如果不查看实际的 pom 文件,很难确定您的问题是什么。

    更新:

    如果您从父项目运行:会发生什么:

     mvn clean install
    
    1. 就您的问题而言,“安装”与“包”有什么不同的行为吗?
    2. 您是否在本地 maven 存储库 (~/.m2/repository/com/mycompany/.../) 中看到 .aar 文件?

    顺便说一句,我对 maven 战争插件从来都不是很满意。我总是最终使用 maven 程序集插件。它似乎工作得更好,更一致。另外,请确保您使用的是最新版本的 maven (2.0.9)。我花了半天时间解决了一个类似的问题,该问题已在最新版本中得到修复。

    【讨论】:

      猜你喜欢
      • 2016-01-16
      • 2015-07-05
      • 2011-09-25
      • 2011-05-29
      • 1970-01-01
      • 2016-05-26
      • 2017-05-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多