CircleCI-Public / maven-orb

Simplify common tasks for building and testing Java projects using Maven on CircleCI.
https://circleci.com/orbs/registry/orb/circleci/maven
MIT License
6 stars 12 forks source link

Orb not working well for multi-module project #4

Closed radek-svanda-elder closed 3 years ago

radek-svanda-elder commented 4 years ago

Orb Version 1.0.0

Describe the bug

Fetching dependencies in commands/with_cache.yml will fail for multi-module maven project because the maven goal dependency:go-offline does not work well with modules.

With the attached project, the step Install dependenies will end with

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for parent 1.0-SNAPSHOT:
[INFO] 
[INFO] parent ............................................. SUCCESS [  1.207 s]
[INFO] world .............................................. SUCCESS [  0.205 s]
[INFO] hello .............................................. FAILURE [  0.262 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.000 s
[INFO] Finished at: 2020-02-04T10:51:01+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project hello: Could not resolve dependencies for project example:hello:jar:1.0-SNAPSHOT: Could not find artifact example:world:jar:1.0-SNAPSHOT -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <args> -rf :hello

To Reproduce

Use this job with project attached

jobs:
  maven-orb-test:
    executor:
      name: maven/default
      tag: '11.0.6'
    steps:
      - checkout
      - maven/with_cache:
          steps:
            - run: mvn compile

And see the logs.

Expected behavior

There are several solutions for this, depending on your project priorities:

Additional context

There is a possible workaround using maven_command: mvn compile

jobs:
  maven-orb-test:
    executor:
      name: maven/default
      tag: '11.0.6'
    steps:
      - checkout
      - maven/with_cache:
          maven_command: mvn compile
          steps:
            - run: mvn compile

Attachments

project.zip

jswart commented 4 years ago

I am also running into this issue with our multi-module project. I don't want 'dependency:go-offline' to be forced with no way to turn it off.

KyleTryon commented 4 years ago

Investigating

KyleTryon commented 4 years ago

A PR has been opened to resolve this issue. Please feel free to leave a review.

radek-svanda-elder commented 4 years ago

@KyleTryon Thanks for looking into this issue.

I guess the proposal in #6 will let me use mentioned go-offline-maven-plugin as they suggest in their example for Gitlab.

That is good enough for me.

wlad commented 4 years ago

any update on this?

skjolber commented 4 years ago

How about autodetecting whether the (root) pom contains modules, and skip the whole offline approach?

jvv-trackunit commented 3 years ago

The issue here is that maven does not correctly detect that some of the dependencies reference other modules that are part of the project.

Luckily, this issue has already been fixed in the Maven dependency plugin version 3.1.2.

CircleCI users keep running into this issue because the maven-dependency plugin defaults to version 2.8 since it is defined in the super pom.

To solve this, I propose using a fixed version of the maven dependency plugin in the maven orb. I have made the following PR for it: #17

As a temporary workaround, you can also put this in your pom to pin the plugin version:

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.1.2</version>
            </plugin>
       </plugins>
    </pluginManagement>
</build>