简体   繁体   中英

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

Collegues, i have subproject utils in my multimodule project. The pom looks like:

<?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.

After that i add next dependency into pom of another subproject

  <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' .

What should i to import com.comp.kort in the second subproject correctly?

mvn dependency:tree on my second subproject shows:

[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.

Provided is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. 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. This scope is only available on the compilation and test classpath, and is not transitive.

You can see here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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