programing

Maven은 mvn 종속성을 실행할 때 형제 모듈을 인식하지 못합니다.

nasanasas 2020. 9. 19. 11:23
반응형

Maven은 mvn 종속성을 실행할 때 형제 모듈을 인식하지 못합니다.


다중 모듈 Maven 프로젝트를 설정하려고하는데 모듈 간 종속성이 올바르게 설정되지 않은 것 같습니다.

나는 가지고있다:

<modules>
  <module>commons</module>
  <module>storage</module>
</modules>

상위 POM (패키징 유형의 pom이 있음)과 하위 디렉토리에 commons/있으며 storage/동일한 이름으로 JAR pom 을 정의합니다.

저장소는 Commons에 따라 다릅니다.

기본 (마스터) 디렉토리에서 다음을 실행 mvn dependency:tree하고 봅니다.

[INFO] Building system
[INFO]    task-segment: [dependency:tree]
[INFO] ------------------------------------------------------------------------
[INFO] [dependency:tree {execution: default-cli}]
[INFO] domain:system:pom:1.0-SNAPSHOT
[INFO] \- junit:junit:jar:3.8.1:test
[INFO] ------------------------------------------------------------------------
[INFO] Building commons
[INFO]    task-segment: [dependency:tree]
[INFO] ------------------------------------------------------------------------
[INFO] [dependency:tree {execution: default-cli}]
...correct tree...
[INFO] ------------------------------------------------------------------------
[INFO] Building storage
[INFO]    task-segment: [dependency:tree]
[INFO] ------------------------------------------------------------------------
Downloading: http://my.repo/artifactory/repo/domain/commons/1.0-SNAPSHOT/commons-1.0-SNAPSHOT.jar
[INFO] Unable to find resource 'domain:commons:jar:1.0-SNAPSHOT' in repository my.repo (http://my.repo/artifactory/repo)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.

Missing:
----------
1) domain:commons:jar:1.0-SNAPSHOT

리액터가 의존성 트리를 성공적으로 처리했기 때문에 분명히 보았지만 "커먼즈"에 대한 의존성이 실패하는 이유는 무엇입니까? 그것은 바로 거기에 있기 때문에 그것을 찾기 위해 '넷에 가지 않을 것입니다 ...

저장을위한 pom :

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <packaging>jar</packaging>
  <parent>
    <artifactId>system</artifactId>
    <groupId>domain</groupId>
    <version>1.0-SNAPSHOT</version>
  </parent>
  <groupId>domain</groupId>
  <artifactId>storage</artifactId>
  <name>storage</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <!-- module dependencies -->
    <dependency>
      <groupId>domain</groupId>
      <artifactId>commons</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>

    <!-- other dependencies -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

제안 해 주셔서 감사합니다!

(편집하다)

To clarify, what I am looking for here is this: I don't want to have to install module X to build module Y which depends on X, given that both are modules referenced from the same parent POM. This makes intuitive sense to me that if I have two things in the same source tree, I shouldn't have to install intermediate products to continue the build. Hopefully my thinking makes some sense here...


I think the problem is that when you specify a dependency Maven expects to have it as jar (or whatever) packaged and available from at least a local repo. I'm sure that if you run mvn install on your commons project first everything will work.


As discussed in this maven mailing list thread, the dependency:tree goal by itself will look things up in the repository rather than the reactor. You can work around this by mvn installing, as previously suggested, or doing something less onerous that invokes the reactor, such as

mvn compile dependency:tree

Works for me.


Realizing this is an older thread but it seems that either the tool evolved or this might have been missed the first time around.

It is possible to perform a build that makes dependencies resolved without installing by doing a reactor build.

If you start your build in the parent that describes the module structure of your project then your dependencies between your modules will be resolved during the build itself through the internal Maven reactor.

Of course this is not the perfect solution since it does not solve the build of a single individual module within the structure. In this case Maven will not have the dependencies in his reactor and will bee looking to resolve it in the repository. So for individual builds you still have to install the dependencies first.

Here is some reference describing this situation.


for me, what led me to this thread was a similar problem and the solution was to ensure all module dependency pom's had

 <packaging>pom</packaging>

the parent had

pom

my model dep had pom - so there was no jar to be found.


The only thing that workd for me : switching to gradle :(

I have

Parent
  +---dep1
  +---war1 (using dep1)

and I can just cd in war1 and use mvn tomcat7:run-war. I always have to install the whole project before, despite war1 references his parent and the parent references war1 and dep1 (as modules) so all dependencies should be known.

I don't understand what the problem is.


In a Maven module structure like this:

- parent
  - child1
  - child2

You will have in the parent pom this:

<modules>
  <module>child1</module>
  <module>child2</module>
</modules>

If you now depend on child1 in child2 by putting the following in your <dependencies> in child2:

<dependency>
  <groupId>example</groupId>
  <artifactId>child1</artifactId>
</dependency>

You will receive an error that the JAR for child1 cannot be found. This can be solved by declaring a <dependencyManagement> block including child1 in the pom for parent:

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>example</groupId>
      <artifactId>child1</artifactId>
      <version>${project.version}</version>
    </dependency>
  </dependencies>
</dependencyManagement>

child1 will now be build when you run a compile or package etc. goal on parent, and child2 will find child1's compiled files.


Bonusing off the answer from Don Willis:

If your build creates test-jars to share test code among your reactor submodules you should use:

mvn test-compile dependency:tree

which will allow dependency:tree to run to completion in this case.


Make sure the module which is failing gets resolved in the pom, is pointing to the right parent by including the configurations in the pom file of the module.

참고URL : https://stackoverflow.com/questions/1677473/maven-doesnt-recognize-sibling-modules-when-running-mvn-dependencytree

반응형