简体   繁体   English

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

[英]How to import artifact from one subproject into another in multimodule project?

Collegues, i have subproject utils in my multimodule project. 同事,我的多模块项目中有子项目utils The pom looks like: 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>

I run command mvn clean install and utils-1.0-SNAPSHOT.jar is created in the local maven repository. 我运行命令mvn clean install并在本地maven存储库中创建了utils-1.0-SNAPSHOT.jar

After that i add next dependency into pom of another subproject 之后,我将下一个依赖项添加到另一个子项目的pom中

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

But when i add import com.comp.kort to classes of my second subproject i receive Can't resolve symbol 'kort' . 但是,当我将import com.comp.kort添加到第二个子项目的类中时,我收到Can't resolve symbol 'kort'

What should i to import com.comp.kort in the second subproject correctly? 我应如何在第二个子项目中正确导入com.comp.kort?

mvn dependency:tree on my second subproject shows: 我的第二个子项目上的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

It seems <scope>provided</scope> is not right, and you can remove it. 似乎<scope>provided</scope>不正确,您可以将其删除。

Provided is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. 提供的就像编译,但是表明您希望JDK或容器在运行时提供依赖项。 For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. 例如,在为Java Enterprise Edition构建Web应用程序时,您将对Servlet API和相关Java EE API的依赖关系设置为提供的范围,因为Web容器提供了这些类。 This scope is only available on the compilation and test classpath, and is not transitive. 该作用域仅在编译和测试类路径上可用,并且不可传递。

You can see here 你可以在这里看到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM