关于Maven 2:在Maven2多项目构建中缺少AAR文件

关于Maven 2:在Maven2多项目构建中缺少AAR文件

Missing aar file in maven2 multi-project build

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

为什么在运行孩子的包裹目标时,父母的包裹目标不包括必要的依赖关系?

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

父POM:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<parent>
    <groupId>companyId</groupId>
    build</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.nationwide.nf</groupId>
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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<parent>
    parent</artifactId>
    <groupId>companyId</groupId>
    <version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>companyId</groupId>
ws-aar</artifactId>
<version>1.0.0-SNAPSHOT</version>
<description/>
<packaging>aar</packaging>
<dependencies>...</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.5</source>
                <target>1.5</target>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.axis2</groupId>
            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>
            axis2-aar-maven-plugin</artifactId>
            <version>1.4</version>
            <extensions>true</extensions>
            <configuration>...</configuration>
        </plugin>
    </plugins>
</build>

战争POM:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<parent>
    parent</artifactId>
    <groupId>companyId</groupId>
    <version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>companyId</groupId>
ws-war</artifactId>
<packaging>war</packaging>
<version>1.0.0-SNAPSHOT</version>
<description/>
<dependencies>
    <dependency>
        <groupId>companyId</groupId>
        ws-aar</artifactId>
        <type>aar</type>
        <version>1.0.0-SNAPSHOT</version>
    </dependency>
    .
    .
    .
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            maven-war-plugin</artifactId>
            <version>2.1-alpha-2</version>
            <configuration>
                <warName>appName</warName>
            </configuration>
        </plugin>
    </plugins>
</build>

谢谢,


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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            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>

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

1
2
3
4
5
6
<dependency>
  <groupId>group-a</groupId>
  artifact-b</artifactId>
  <version>1.0</version>
  <type>aar</type>
</dependency>

在没有看到您实际的pom文件的情况下很难确定您的问题是什么。

更新:

如果从父项目中运行:

1
 mvn clean install
  • 就您的问题而言,"安装"与"软件包"的行为是否有所不同?
  • 您是否在本地Maven存储库(?/ .m2 / repository / com / mycompany /.../)中看到.aar文件?
  • 附带说明一下,我从未对Maven War插件感到非常满意。 我总是最终使用maven程序集插件。 它似乎工作得更好并且更加一致。 另外,请确保您使用的是最新版本的maven(2.0.9)。 我花了半天时间来解决类似问题,该问题已在最新版本中修复。


    推荐阅读