如何在多模块项目中将工件从一个子项目导入另一个子项目?

时间:2016-07-26 07:14:26

标签: java maven pom.xml multi-module

Collegues,我在我的multimodule项目中有子项目utils。 pom看起来像:

<?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">
    <parent>
        <artifactId>parent</artifactId>
        <groupId>com.comp.kort</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>utils</artifactId>


<dependencies>
    <dependency>
        <groupId>com.sun.mail</groupId>
        <artifactId>javax.mail</artifactId>
        <version>1.5.5</version>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>

</dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>${project.build.sourceJdk}</source>
                    <target>${project.build.targetJdk}</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

我运行命令mvn clean install,并在本地maven存储库中创建utils-1.0-SNAPSHOT.jar

之后我将下一个依赖项添加到另一个子项目的pom中

  <dependency>
            <groupId>com.comp.kort</groupId>
            <artifactId>utils</artifactId>
            <version>1.0-SNAPSHOT</version>
            <scope>provided</scope>
  </dependency>

但是当我将import com.comp.kort添加到我的第二个子项目的类中时,我收到了Can't resolve symbol 'kort'

我应该在第二个子项目中正确导入com.comp.kort?

我的第二个子项目中的

mvn dependency:tree显示:

[INFO] com.comp.kort:kort-sp-integration:jar:1.0-SNAPSHOT
[INFO] +- org.springframework.batch:spring-batch-core:jar:3.0.7.RELEASE:compile
[INFO] |  +- com.ibm.jbatch:com.ibm.jbatch-tck-spi:jar:1.0:compile
[INFO] |  |  \- javax.batch:javax.batch-api:jar:1.0:compile
[INFO] |  +- com.thoughtworks.xstream:xstream:jar:1.4.7:compile
[INFO] |  |  +- xmlpull:xmlpull:jar:1.1.3.1:compile
[INFO] |  |  \- xpp3:xpp3_min:jar:1.1.4c:compile
[INFO] |  +- org.codehaus.jettison:jettison:jar:1.2:compile
[INFO] |  +- org.springframework.batch:spring-batch-infrastructure:jar:3.0.7.RELEASE:compile
[INFO] |  |  \- org.springframework.retry:spring-retry:jar:1.1.0.RELEASE:compile
[INFO] |  +- org.springframework:spring-aop:jar:4.0.5.RELEASE:compile
[INFO] |  |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  +- org.springframework:spring-beans:jar:4.0.5.RELEASE:compile
[INFO] |  +- org.springframework:spring-context:jar:4.0.5.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-expression:jar:4.0.5.RELEASE:compile
[INFO] |  +- org.springframework:spring-core:jar:4.0.5.RELEASE:compile
[INFO] |  \- org.springframework:spring-tx:jar:4.0.5.RELEASE:compile
[INFO] +- org.springframework:spring-jdbc:jar:4.2.6.RELEASE:compile
[INFO] +- org.apache.commons:commons-dbcp2:jar:2.1.1:compile
[INFO] |  +- org.apache.commons:commons-pool2:jar:2.4.2:compile
[INFO] |  \- commons-logging:commons-logging:jar:1.2:compile
[INFO] +- commons-io:commons-io:jar:2.2:compile
[INFO] +- log4j:log4j:jar:1.2.17:compile
[INFO] +- com.microsoft.sqlserver:sqljdbc4:jar:4.2:compile
[INFO] +- org.apache.commons:commons-lang3:jar:3.4:compile
[INFO] +- junit:junit:jar:4.12:test
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- com.sun.mail:javax.mail:jar:1.5.5:compile
[INFO] |  \- javax.activation:activation:jar:1.1:compile
[INFO] \- com.comp.kort:utils:jar:1.0-SNAPSHOT:compile

1 个答案:

答案 0 :(得分:-2)

似乎<scope>provided</scope>不正确,您可以将其删除。

  

提供与compile非常相似,但表示您希望JDK或容器在运行时提供依赖性。例如,在为Java Enterprise Edition构建Web应用程序时,您可以将Servlet API和相关Java EE API的依赖关系设置为提供的范围,因为Web容器提供了这些类。此范围仅在编译和测试类路径中可用,并且不可传递。

您可以看到here