0

I have a web-app which provides an implementation of an API that I have written. So, I have a set of three artifacts: my-webapp (war), my-api (jar) and my-impl (jar). The pom's are straight-forward where: my-impl lists my-api as a dependency, and my-webapp lists my-impl as a dependency. When I run mvn install, I expect my-impl to pull in my-api during packaging into WEB-INF/lib. But it is pulling in only my-impl.

What am I doing wrong here? Or is it not expected to work this way?

Update: If this helps, I keep getting this warning:

[WARN] The POM for mine:my-impl:jar:1.1.0.0 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details

The POM's are as follows:

Packager:

<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>mine</groupId>
    <artifactId>my-webapp-packager</artifactId>
    <version>${product.version}</version>
    <packaging>pom</packaging>
    <name>Webapp Packager</name>
    <description>Webapp Packager</description>
    <modules>
        <module>my-webapp</module>
        <module>my-api</module>
        <module>my-impl</module>
    </modules>
</project>

Webapp:

<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>
    <parent>
        <groupId>mine</groupId>
        <artifactId>my-webapp-packager</artifactId>
        <version>${product.version}</version>
    </parent>
    <artifactId>my-webapp</artifactId>
    <packaging>war</packaging>
    <name>Webapp</name>
    <description>Webapp</description>
    <dependencies>
        <dependency>
            <groupId>mine</groupId>
            <artifactId>my-impl</artifactId>
            <version>${product.version}</version>
        </dependency>
    </dependencies>
</project>

API:

<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>
    <parent>
        <groupId>mine</groupId>
        <artifactId>my-webapp-packager</artifactId>
        <version>${product.version}</version>
    </parent>
    <artifactId>my-api</artifactId>
    <packaging>jar</packaging>
    <name>API</name>
    <description>API</description>
</project>

Implementation:

<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>
    <parent>
        <groupId>mine</groupId>
        <artifactId>my-webapp-packager</artifactId>
        <version>${product.version}</version>
    </parent>
    <artifactId>my-impl</artifactId>
    <packaging>jar</packaging>
    <name>Impl</name>
    <description>Impl</description>
    <dependencies>
        <dependency>
            <groupId>mine</groupId>
            <artifactId>my-api</artifactId>
            <version>${product.version}</version>
        </dependency>
    </dependencies>
</project>
4

1 回答 1

1

正如你现在所拥有的,你的“打包器”POM 既是一个聚合器(因为它有模块)又是一个父级(因为所有模块都在它们的<parent>元素中引用它)。因此,“打包器”POM必须有一个明确的版本,你不能使用 ${project.version} 占位符。

<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>mine</groupId>
    <artifactId>my-webapp-packager</artifactId>
    <version>0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>Webapp Packager</name>
    <description>Webapp Packager</description>
    <modules>
        <module>my-webapp</module>
        <module>my-api</module>
        <module>my-impl</module>
    </modules>
</project>

在子模块中,<parent>元素将如下所示:

<parent>
    <groupId>mine</groupId>
    <artifactId>my-webapp-packager</artifactId>
    <version>0.1-SNAPSHOT</version>
</parent>

然后, amvn clean install应该工作。

于 2013-06-17T16:02:31.213 回答