1

With Maven 3.8.2

I have a plugin that I download from a custom Maven repository:

$ mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.2:get \
-DremoteRepositories=excelfore.private::::https://some_url \
-Dartifact=com.excelfore:appshack-maven-plugin:4.2133-RC1:maven-plugin
...
[INFO] BUILD SUCCESS

Now I just want to run the plugin:

$ mvn -e com.excelfore:appshack-maven-plugin:4.2133-RC1:run-self-test

which results into:

[ERROR] Plugin com.excelfore:appshack-maven-plugin:4.2133-RC1 or one of its dependencies could not be resolved: Failure to find com.excelfore:appshack-maven-plugin:jar:4.2133-RC1 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]

How do I tell Maven to just use the files it's downloaded earlier?

I've tried -o, this just changes to:

[ERROR] Plugin com.excelfore:appshack-maven-plugin:4.2133-RC1 or one of its dependencies could not be resolved: Cannot access central (https://repo.maven.apache.org/maven2) in offline mode and the artifact com.excelfore:appshack-maven-plugin:jar:4.2133-RC1 has not been downloaded from it before. -> [Help 1]

-npu doesn't seem to do anything, it shows a warning about this option being deprecated, and the error is the same.

Using -X I can see these messages:

[DEBUG] Using local repository at /home/vps/.m2/repository
[DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10.0 for /home/vps/.m2/repository
[INFO] Scanning for projects...
[DEBUG] Extension realms for project org.apache.maven:standalone-pom:pom:1: (none)
[DEBUG] Looking up lifecycle mappings for packaging pom from ClassRealm[plexus.core, parent: null]
[DEBUG] Verifying availability of /home/vps/.m2/repository/com/excelfore/appshack-maven-plugin/4.2133-RC1/appshack-maven-plugin-4.2133-RC1.pom from [central (https://repo.maven.apache.org/maven2, default, releases)]
[WARNING] The POM for com.excelfore:appshack-maven-plugin:jar:4.2133-RC1 is missing, no dependency information available
[DEBUG] Verifying availability of /home/vps/.m2/repository/com/excelfore/appshack-maven-plugin/4.2133-RC1/appshack-maven-plugin-4.2133-RC1.jar from [central (https://repo.maven.apache.org/maven2, default, releases)]

Of course all the files are there, and I even verified that SHA1 sums match:

[vps@hornet]~$ ll ~/.m2/repository/com/excelfore/appshack-maven-plugin/4.2133-RC1/
-rw-rw-r--. 1 vps 317291 Aug 19 12:43 appshack-maven-plugin-4.2133-RC1.jar
-rw-rw-r--. 1 vps    341 Aug 19 12:43 appshack-maven-plugin-4.2133-RC1.jar.lastUpdated
-rw-rw-r--. 1 vps     40 Aug 19 12:43 appshack-maven-plugin-4.2133-RC1.jar.sha1
-rw-rw-r--. 1 vps   3248 Aug 19 12:43 appshack-maven-plugin-4.2133-RC1.pom
-rw-rw-r--. 1 vps    341 Aug 19 12:43 appshack-maven-plugin-4.2133-RC1.pom.lastUpdated
-rw-rw-r--. 1 vps     40 Aug 19 12:43 appshack-maven-plugin-4.2133-RC1.pom.sha1
-rw-rw-r--. 1 vps    252 Aug 19 12:43 _remote.repositories

It seems that I'm missing something silly, and it seems that sometimes this works just fine, but I often run into this brick wall. I expect Maven not to try to synchronize artifacts that have been successfully downloaded.

I assume the problem is that Maven doesn't know about the private repository when it runs the plugin, but I need to run it outside of any project (i.e. no POM file), and AFAIU, there is no way to define repositories in the ~/.m2/settings.xml (only servers, which won't help).

What is weirder, however, is that this works with snapshots.

$ mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.2:get \
 -DremoteRepositories=excelfore.private::::https://some_url \
 -Dartifact=com.excelfore:appshack-maven-plugin:4.2132-SNAPSHOT:maven-plugin
...
[INFO] BUILD SUCCESS

$ /opt/maven/apache-maven-3.8.2/bin/mvn -X \
com.excelfore:appshack-maven-plugin:4.2132-SNAPSHOT:run-self-test
...
[DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10.0 for /home/vps/.m2/repository
[INFO] Scanning for projects...
[DEBUG] Extension realms for project org.apache.maven:standalone-pom:pom:1: (none)
[DEBUG] Looking up lifecycle mappings for packaging pom from ClassRealm[plexus.core, parent: null]
[DEBUG] Could not find metadata com.excelfore:appshack-maven-plugin:4.2132-SNAPSHOT/maven-metadata.xml in local (/home/vps/.m2/repository)
[DEBUG] Could not find metadata com.excelfore:appshack-maven-plugin:4.2132-SNAPSHOT/maven-metadata.xml in local (/home/vps/.m2/repository)
[DEBUG] Could not find metadata com.excelfore:appshack:4.2132-SNAPSHOT/maven-metadata.xml in local (/home/vps/.m2/repository)
[DEBUG] === REACTOR BUILD PLAN ================================================
[DEBUG] Project: org.apache.maven:standalone-pom:pom:1
[DEBUG] Tasks:   [com.excelfore:appshack-maven-plugin:4.2132-SNAPSHOT:run-self-test]

Judging by the debug output, it doesn't do this "availability verification" with snapshots. However, using -U flag makes absolutely no difference.

Pawel Veselov
  • 3,996
  • 7
  • 44
  • 62
  • „_there is no way to list repositories in the `~/.m2/settings.xml`_“ is not true. Usually the first setting there is `` the default of which is `${user.home}/.m2/repository`. – Gerold Broser Aug 19 '21 at 22:00
  • @GeroldBroser That tag specifies the (non-default) location of the local repository, it doesn't define a repository. – Pawel Veselov Aug 19 '21 at 23:22
  • The first part of your sentence is exactly what I meant. I'm not a native English speaker. Is there a, maybe subtle, difference between "specify" and "define" (regarding config settings) I'm not aware of (yet)? You don't run this `...:run-self-test` goal on a project (with a POM), do you? – Gerold Broser Aug 19 '21 at 23:54
  • @GeroldBroser Yes, there is no project – Pawel Veselov Aug 20 '21 at 00:09
  • Is there a good reason why a repository manager is not used? – khmarbaise Aug 25 '21 at 19:35
  • @khmarbaise I must be missing something, but I don't understand the question. A repository manager is being used, it's the private repository. – Pawel Veselov Aug 25 '21 at 19:39
  • If a repository manager is used than this: `(https://repo.maven.apache.org/maven2) in offline mode and the artifact` is something which should never appear...another question is: Why do you use dependency plugin to get dependencies downloaded? why not simply adding them as dependency? – khmarbaise Aug 25 '21 at 20:18
  • @khmarbaise I'm sorry, I don't understand where you are leading with this. There is no project involved, the problem is downloading and executing a plugin, from a private repository, without any associated project. If you believe this can be solved in a specific way, I would appreciate an answer detailing that solution – Pawel Veselov Aug 25 '21 at 20:20

1 Answers1

1

FWIW, I've put together this Maven extension that lets me do what I want, by adding additional repositories to the project representation at runtime: https://github.com/veselov/mvn-project-default

Once enabled and configured, the private repositories are queried to get whatever artifacts Maven needs to pull during execution.

Pawel Veselov
  • 3,996
  • 7
  • 44
  • 62