Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make maven use credentials when executing dependency plugin from command line

I have a private Maven repository. It's defined in pom.xml of the project

    <repository>
        <id>some.id</id>
        <url>https://some.host/artifactory/some.id</url>
    </repository>

In my ~/.m2/settings.xml, I have proper authentication block:

    <server>
        <id>some.id</id>
        <username>[email protected]</username>
        <password>{some-fancy-password-hash-goes-here}</password>
    </server>

When building the project, Maven is able to access the repository without any problems, as it's supposed to be. In debugging output, I can see it applying the credentials.

But when I try to download an artifact directly, it doesn't look like Maven is even considering the settings file.

mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.1:get \
  -DremoteRepositories=some.id::::https://some.host/artifactory/some.id \
  -Dartifact=groupId:artifactId:1.1.1

The username is not transmitted. I can see in the debug output, that the BasicRepositoryConnector is invoked without username/password combination.

So the question goes - can a plugin be invoked so that whatever process makes Maven consider using the authentication stated in its settings file is executed?

like image 533
Pawel Veselov Avatar asked Nov 20 '18 00:11

Pawel Veselov


People also ask

How do I force Maven to download dependencies from remote repository?

We can use -U/--update-snapshots flag when building a maven project to force maven to download dependencies from the remote repository. Here, -U,--update-snapshots : Forces a check for missing releases and updated snapshots on remote repositories.

How use mvn command line?

Running a Maven build via the command line To build a Maven project via the command line, you use the mvn command from the command line. The command must be executed in the directory which contains the relevant pom file. You pass the build life cycle, phase or goal as parameter to this command.


1 Answers

It doesn't look like the plugin is using the saved credentials when remoteRepositories property is used. Testing using repositoryId instead worked as expected for me.

mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.1:get -DrepositoryId=some.id -Dartifact=groupId:artifactId:1.1.1

The effective pom must contain repository and url for the repo. If you plan to run this in an empty directory without any pom.xml then your repository definition will need to be moved to settings.xml

like image 110
Revive Avatar answered Nov 15 '22 06:11

Revive