carlossg / docker-maven

Official Docker image with Maven
Apache License 2.0
524 stars 423 forks source link

»Unknown lifecycle phase "/root/.m2"« when using mvnw #301

Open bmarwell opened 1 year ago

bmarwell commented 1 year ago

Hi!

I tried your images, but I am unable to use mvnw. The wrapper script seems to do a bit too much of magic. The maven image was chosen because I could not find any other image with both git and java installed.

Maven command

https://github.com/georgberky/dependency-update-maven-plugin/blob/47490170e35f70e986fa843860eb5395e942d392/.drone.yml#L17-L25

      - |
        ./mvnw \
          --show-version \
          --fail-at-end \
          --batch-mode \
          --no-transfer-progress \
          verify \
          site site:stage \
          -Pdocs

Drone CI output

https://cloud.drone.io/georgberky/dependency-update-maven-plugin/142/1/2

+ git config --global user.email "noreply@dependency-plugin.invalid"
+ git config --global user.name "dependency-update-maven-plugin"
+ ./mvnw   --show-version   --fail-at-end   --batch-mode   --no-transfer-progress   verify   site site:stage   -Pdocs

--2022-10-03 19:44:20--  https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar
Resolving repo.maven.apache.org (repo.maven.apache.org)... 151.101.208.215
Connecting to repo.maven.apache.org (repo.maven.apache.org)|151.101.208.215|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 58727 (57K) [application/java-archive]
Saving to: ‘/drone/src/.mvn/wrapper/maven-wrapper.jar’

     0K .......... .......... .......... .......... .......... 87% 12.5M 0s
    50K .......                                               100% 15.2M=0.004s

2022-10-03 19:44:20 (12.8 MB/s) - ‘/drone/src/.mvn/wrapper/maven-wrapper.jar’ saved [58727/58727]

Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
Maven home: /root/.m2/wrapper/dists/apache-maven-3.8.6-bin/1ks0nkde5v1pk9vtc31i9d0lcd/apache-maven-3.8.6
Java version: 1.8.0_345, vendor: Temurin, runtime: /opt/java/openjdk/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-154-generic", arch: "amd64", family: "unix"
[INFO] Scanning for projects...
[INFO] 
[INFO] --< io.github.georgberky.maven.plugins.depsupdate:dependency-update-maven-plugin >--
[INFO] Building io.github.georgberky.maven.plugins.depsupdate:dependency-update-maven-plugin 0.9.0-SNAPSHOT
[INFO] ----------------------------[ maven-plugin ]----------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.230 s
[INFO] Finished at: 2022-10-03T19:44:23Z
[INFO] ------------------------------------------------------------------------
[ERROR] Unknown lifecycle phase "/root/.m2". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [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/LifecyclePhaseNotFoundException

... will add -e (--errors) and see what it says.

bmarwell commented 1 year ago

Build with --errors does not give any more useful information. https://cloud.drone.io/georgberky/dependency-update-maven-plugin/144/1/2

carlossg commented 1 year ago

this means that something is passing $HOME to mvn as argument

I cannot try it because going to the link you provided I cannot clone that commit

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

carlossg commented 1 year ago

found the PR, the problem is that mvnw takes MAVEN_CONFIG as args, and these images set MAVEN_CONFIG to the .m2 dir

# Provide a "standardized" way to retrieve the CLI args that will
# work with both Windows and non-Windows executions.
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"

so you would need to unset MAVEN_CONFIG before calling mvnw

it was reported also as https://issues.jenkins.io/browse/JENKINS-47890

carlossg commented 1 year ago

this was actually fixed or mitigated 5 years ago in 0490eff01e529b2d94789511b008d01a7b314953 when using the entrypoint