I am trying to publish third-party private package directly to my Azure Artifacts feed with mvn deploy:deploy-file command like this:
mvn deploy:deploy-file -Dpackaging="jar" -DrepositoryId="PXXXXX-inccoming" -Durl="https://pkgs.dev.azure.com/XxxXxxxXxxx/XxxXxx/_packaging/PXXXXX-incoming/maven/v1" -DgroupId="pl.group.id" -DartifactId="artifact" -Dversion="0.0.2" -Dfile="C:\path\pl\group\id\0.0.2\artifact-0.0.2.jar"
But I am getting strange error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file (default-cli) on project CAST_2015: Failed to deploy artifacts: Could not transfer artifact pl.group.id:artifact:jar:0.0.2 from/to PXXXXX-inccoming (https://pkgs.dev.azure.com/XxxXxxxXxxx/XxxXxx/_packaging/PXXXXX-incoming/maven/v1): Transfer failed for https://pkgs.dev.azure.com/XxxXxxxXxxx/XxxXxx/_packaging/PXXXXX-incoming/maven/v1/pl/group/id/artifact/0.0.2/artifact-0.0.2.jar 401 Unauthorized ProxyInfo{host='proxy-host', userName='null', port=8080, type='http', nonProxyHosts='null'}
The provided user has full access for packaging in Azure.
Both proxy and server settings are actually in my setting.xml file.
What am I doing wrong?
Azure Artifacts deploy packages
When we receiving a 401 it is because maven is sending the wrong login credentials, or no credentials at all.
To resolve this issue, please add the following configuration to the <servers>...</servers> configuration node in the maven setting configuration file:
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
Note:
The id configured in setting.xml must be the same as the id
configured in pom.xml.
If you try to publish something to a releases repository and that
version already exists in the repository
If it not work for you, please check below thread for some more details:
Why am I getting a "401 Unauthorized" error in Maven?
Related
Please tell me what i do wrong.
I download maven project from springboot.io and import to IDE(intelliJ).
Start to deploy I get error
> [ERROR] Failed to execute goal
> org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy
> (default-deploy) on project securing-web-initial: Deployment failed:
> repository element was not specified in the POM inside
> distributionManagement element or in
> -DaltDeploymentRepository=id::layout::url parameter -> [Help 1] [ERROR]
I read like this Problem with deploying spring boot application and add to POM.xml
<distributionManagement>
<repository>
<id>internal.repo</id>
<name>Internal repo</name>
<url>E:\!Distrib\repo</url>
</repository>
</distributionManagement>
<repositories>
<repository>
<id>example-repo</id>
<name>Example Repository</name>
<url>
E:\!Distrib\repo
</url>
</repository>
</repositories>
Nothing changed.
If I use a URL C:\!Users\tgdavies\testrepo I get the error message: Failed to deploy artifacts/metadata: Cannot access C:\!Users\tgdavies\testrepo with type default using the available connector factories: BasicRepositoryConnectorFactory
If I use file:C:\Users\tgdavies\testrepo deploy succeeds.
But your issue is that you do not need to run mvn deploy. Read the tutorial you linked to -- it does not suggest running mvn deploy. To test your code
If you use Maven, you can run the application by using ./mvnw spring-boot:run. Alternatively, you can build the JAR file with ./mvnw clean package and then run the JAR file, as follows:
java -jar target/gs-rest-service-0.1.0.jar
Import I made correctly. It is very easy. I suggested it need a lot of task after import maven project because Run button was not active. As additional automatically was open maven window with deploy and install items)).
intelliJ did not make configuration for run. As a result run button was not active.
I need to set flyway migration and I don't want to put password and username in pom.xml, I created flyway.properties file, but it's not working, I'm getting this error
Failed to execute goal org.flywaydb:flyway-maven-plugin:6.5.1:clean (default-cli) on project entesting: org.flywaydb.core.api.FlywayException: Unable to connect to the database. Configure the url, user and password!
flyway.properties file is in same directory as pom.xml
flyway.user=sa
flyway.password=passwordForThis
flyway.url=jdbc:sqlserver://172.23.176.144;database=DB_Name
flyway.locations=filesystem:src/main/resources/db/migration
flyway.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
pom.xml flyway plugin config:
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>6.5.1</version>
<configuration>
<url>jdbc:sqlserver://172.23.176.144;database=DB_Name</url>
<user>sa</user>
<password>passwordForThis</password>
</configuration>
</plugin>
To summarize I don't want to add password, username etc. in pom.xml(that works), I want it to be in flyway.propeties.
Flyway can be configured in a number of ways beyond directly putting it into the maven pom.xml. See documentation on configuring the maven plugin
The contents of the properties file you showed looks like the contents of a flyway.conf file.
Flyway will search for and automatically load the <user-home>/flyway.conf config file if present.
It is also possible to point Flyway at one or more additional config files. This is achieved by supplying the System property flyway.configFiles as follows:
mvn -Dflyway.configFiles=path/to/myAlternativeConfig.conf flyway:migrate
See https://flywaydb.org/documentation/maven/#config-files for more information.
Alternatively for storing the database user and password, Maven settings.xml files can also be used:
<settings>
<servers>
<server>
<!-- By default Flyway will look for the server with the id 'flyway-db' -->
<!-- This can be customized by configuring the 'serverId' property -->
<id>flyway-db</id>
<username>myUser</username>
<password>mySecretPwd</password>
</server>
</servers>
</settings>
I have a Maven project and want to build it using mvn clean deploy so that the built artifact is deployed into a Nexus repository.
The access data (username and password) for that repository are stored in Jenkins credentials.
I want to call mvn deploy in Jenkins so that the credentials for that Nexus repository are read from Jenkins (not hardcoded in settings.xml).
How can I do it, if I cannot access settings.xml on the Jenkins server?
Update 1:
I created an entry in "Config File Management" (JENKINS_URL/configfiles/index) with following data:
Type: Maven settings.xml
Replace All: Yes
Server ID: myServer
Credentials: Credentials for the Nexus repository
Content:
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>myServer</id>
<username>foo</username>
<password>bar</password>
</server>
</servers>
</settings>
myServer is also used in the pom.xml of the artifact I want to build:
<distributionManagement>
<repository>
<id>myServer</id>
<url>http://nexus.mycompany.com</url>
</repository>
</distributionManagement>
In the configuration of the job, I include those settings as shown below. Nexus settings.xml is the configuration from "Config File Management".
But it does not work -- I get "Forbidden" error when the build attempts to deploy artifacts to Nexus.
Update 2: When I run mvn -X deploy locally with the same credentials as in Jenkins (stored in my local settings.xml), I see following output:
[DEBUG] Failed to decrypt password for server XXX release repository: org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException: java.io.FileNotFoundException: /XXXXXXXXXXXXXXX/.m2/settings-security.xml (No such file or directory)
org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException: org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException: java.io.FileNotFoundException: /XXXXXXXXXXXXXXX/.m2/settings-security.xml (No such file or directory)
at org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher.decrypt(DefaultSecDispatcher.java:121)
at org.apache.maven.settings.crypto.DefaultSettingsDecrypter.decrypt(DefaultSettingsDecrypter.java:107)
at org.apache.maven.settings.crypto.DefaultSettingsDecrypter.decrypt(DefaultSettingsDecrypter.java:63)
at org.apache.maven.internal.aether.DefaultRepositorySystemSessionFactory.newRepositorySession(DefaultRepositorySystemSessionFactory.java:165)
However, the password in settings.xml is not encrypted at all:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository/>
<interactiveMode/>
<offline/>
<pluginGroups/>
<servers>
<server>
<id>NEXUS_REPOSITORY_SNAPSHOTS</id>
<username>user</username>
<password>password</password>
</server>
</servers>
<mirrors/>
<proxies/>
<profiles/>
<activeProfiles/>
</settings>
I found a report about similar error here.
You can use the Jenkins config-file-provider plugin ( link: https://plugins.jenkins.io/config-file-provider/ ) to create one or several Maven settings.xml files.
NOTE: Really this helps also if you need differents settings.xml for
different projects.
Then on the maven deploy step of your Jenkins project you can select to point to one of the settings.xml files defined ( instead of pointing to the general Jenkins server /.m2/settings.xml )
I have auto-generated java code I want to deploy in our maven repo. The generated code has a pom.xml without the repo info. I what to know if I can deploy the complete maven project in my repo without touching the pom. And by complete maven project, I mean not only the final jar using the file-deploy maven command.
The repo has security enabled and requires usr/pass
I found a way. You need to add the server to the settings file as following:
<servers>
<server>
<id>my-server</id>
<username>user</username>
<password>pass</password>
</server>
</servers>
then I deploy using the following maven command (replacing <url> for the target repo):
mvn deploy -D"altDeploymentRepository=my-server::default::<url>"
I'm trying to accessing a server with a maven repo. From my windows machine at work I can access it with my company login. With my mac I can access the server if I connect to it and enter in my windows credentials.
Here is the part of my pom with the rep:
<repositories>
<repository>
<id>repo.id</id>
<url>file:////servername/MavenRepo</url>
<!-- use snapshot version -->
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
here is the part of the settings.xml that I'm using to try to set credentials to access that maven repo. What am I doing wrong?
<server>
<id>repo.id</id>
<username>domain\username</username>
<password>password</password>
</server>
The error is:
[ERROR] Failed to execute goal on project Company-Project: Could not resolve dependencies for project Company-Project:Company-Project:jar:DEVELOP-1.0-SNAPSHOT: Failed to collect dependencies at Company-ProjectName:Company-ProjectName:jar:1.0-SNAPSHOT: Failed to read artifact descriptor for Company-ProjectName:Company-ProjectName:jar:1.0-SNAPSHOT: Could not transfer artifact Company-ProjectName:Company-ProjectName:pom:1.0-SNAPSHOT from/to com.Company.maven (file:////Server.Company.corpnet.local/JenkinsMavenRepo): Repository path /Server.Company.corpnet.local/JenkinsMavenRepo does not exist, and cannot be created. -> [Help 1]
It seems that maven could not find the repository on the file system.
file:////Server.Company.corpnet.local/JenkinsMavenRepo): Repository path /Server.Company.corpnet.local/JenkinsMavenRepo does not exist
Have you mounted the repository file system correctly?
Check if you can access the directory /Server.Company.corpnet.local/JenkinsMavenRepo in the Terminal.
PS
I always would prefer a repository server such as nexus. Is that an option?
Turns out using windows as a filestore for a maven repo is proprietary. I setup a IIS server (http) pointing to that directory which resolves the issue.