401 Unauthorized when running mvn compile - maven

I'm running mvn compile -e -X in a JMeter project directory from cmd prompt and I'm getting a 401 unauthorized:
What I'd imagine the HTTP request to be, works fine in Powershell and gives me a 200 response.
So the token I'm using does work.
$MyPat = 'passwordHere'
$B64Pat = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(":$MyPat"))
$result = Invoke-WebRequest -UseBasicParsing -Uri 'https://mycompanyproject.pkgs.visualstudio.com/_packaging/maven/maven/v1/microsoft/aspnet/signalr/signalr-client-sdk/1.0/signalr-client-sdk-1.0.pom' -Headers #{"Authorization"="Basic $B64Pat"}
I tried running Wireshark to view the HTTP request but nothing comes up for some reason.
Here is the settings.xml:
<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">
<servers>
<server>
<id>maven#Release</id>
<username>mycompanyproject</username>
<password>passwordHere</password>
</server>
<server>
<id>mycompany</id>
<username>mycompanyproject</username>
<password>passwordHere</password>
</server>
</servers>
</settings>
Here's is the pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>au.com.mycompany</groupId>
<artifactId>mycompany-jmeter-plugins</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>mycompany</id>
<url>https://mycompanyproject.pkgs.visualstudio.com/_packaging/mycompany/maven/v1</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>mycompanyproject-visualstudio-com-mycompanyproject-maven</id>
<url>https://mycompanyproject.pkgs.visualstudio.com/_packaging/maven/maven/v1</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>mycompany</id>
<url>https://mycompanyproject.pkgs.visualstudio.com/_packaging/mycompany/maven/v1</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<snapshotRepository>
<id>mycompanyproject-visualstudio-com-mycompanyproject-maven</id>
<url>https://mycompanyproject.pkgs.visualstudio.com/_packaging/maven/maven/v1</url>
</snapshotRepository>
</distributionManagement>
<modules>
<module>signalr</module>
<module>hoconreader</module>
<module>propertyfilereader</module>
<module>jsonbackendlistener</module>
<module>samplerjavaexample</module>
<module>tokengenerator</module>
<module>data-tenantdownload</module>
<module>data-invoicegenius</module>
<module>data-unittests</module>
<module>common</module>
<module>ratio-data-generator</module>
<module>timinglistener</module>
</modules>
</project>

I should have paid closer attention to the suggestions at:
https://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
It was because the for my in settings.xml didn't match what I had in pom.xml.
Making them the same fixed my issue.

Related

Unrecognized Tag 'repositores'

upon doing a mvn clean I am greeted with an error
[WARNING] Unrecognised tag: 'repositories' (position: START_TAG seen ...tp://maven.apache.org/xsd/settings-1.0.0.xsd">\n\n <repositories>... #6:19) # /Users/geronimo.sanpascual/.m2/settings.xml, line 6, column 19
Here's my m2.
<?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">
<repositories>
<repository>
<id>artifactory</id>
<url>https://artifactory.sample.test/sample/sample</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>mvnrepository</id>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
<servers>
<server>
<id>artifactoryuser</id>
<username>user</username>
<password>password</password>
</server>
</servers>
</settings>
I tried adding it to a <profiles> </profiles tag but still didnt work.
Any help would be appreciated. thank you.
--Added the whole POM file--
According to http://maven.apache.org/xsd/settings-1.0.0.xsd you can't have a <repositories> tag directly in <settings>, you should include it into a <profile> like that
<settings ...>
<profiles>
<profile>
<id>some_profile_name</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>artifactory</id>
<url>https://artifactory.sample.test/sample/sample</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>mvnrepository</id>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
</profile>
</profiles>
...
</settings>

Jenkins maven release goes to lib-snapshot repository

I am having setup where Jenkins is used to release maven project to artifactory. I see everything is working fine what maven release do like incrementing pom versions, creating tag but it is not uploading to lib-release repo instead it is uploading it to lib-snapshot repo.
I verified my settings.xml and saw it uses different ids for snapshot and release repo. What else can I check to fix this issue?
This is my settings.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--<settings.version>1.0.1</settings.version>-->
<!--<settings.region>IL</settings.region>-->
<!--<settings.type>server</settings.type>-->
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<servers>
<server>
<id>artifactory_server</id>
<username>deploy_user</username>
<password>xxxxxxxxxxxxxxxxxxx</password>
</server>
</servers>
<profiles>
<profile>
<repositories>
<repository>
<snapshots />
<releases>
<enabled>false</enabled>
</releases>
<id>artifactory-snapshots</id>
<name>libs-snapshot</name>
<url>http://artifactory.example.com/artifactory/libs-snapshot</url>
</repository>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>artifactory-release</id>
<name>libs-release</name>
<url>http://artifactory.example.com/artifactory/libs-release</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
<id>central</id>
<name>plugins-release</name>
<url>http://artifactory.example.com/artifactory/plugins-release</url>
</pluginRepository>
<pluginRepository>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
<id>snapshots</id>
<name>plugins-snapshot</name>
<url>http://artifactory.example.com/artifactory/plugins-snapshot</url>
</pluginRepository>
</pluginRepositories>
<id>artifactory</id>
</profile>
</profiles>
<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>
</settings>
It's completely up to Maven and POM definitions.
By default every Jenkins run are threaten as Snapshots but you can control them by
Repositories with
<snapshots>
<enabled>false</enabled>
</snapshots>
And using maven-release-plugin https://maven.apache.org/maven-release/maven-release-plugin/examples/prepare-release.html

Can't import any downloaded maven dependency, if IntelliJ IDEA behind proxy

I was configure my settings.xml for corp proxy server like this
<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">
<activeProfiles>
<activeProfile>securecentral</activeProfile>
</activeProfiles>
<profiles>
<profile>
<id>securecentral</id>
<repositories>
<repository>
<id>central</id>
<url>http://repo1.maven.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://repo1.maven.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<proxies>
<proxy>
<active>true</active>
<protocol>http</protocol>
<host>***.***.***.***</host>
<port>****</port>
<username>******</username>
<password>******</password>
<nonProxyHosts>www.google.com|*.example.com</nonProxyHosts>
</proxy>
</proxies>
</settings>
and got the possibility of downloading dependencies. But if with downloading its ok, when i try to import something to class, idea cant find any downloaded dependency and mark as red all after top domain level. Can to see only base libraries (which was included by default) when i put the dot after org. for example.
In .m2 folder all necessary libraries is downloaded
In settings -> build tools -> maven all as default
Any new dependencies downloads successfully
pom.xml without any errors
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>groupId1</groupId>
<artifactId>untitled</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.4.0</version>
</dependency>
</dependencies>
</project>
Somebody have any idea about that?
Any advise will be helpful!
Thanks a lot guys!

Nexus group by SNAPSHOT

I have Nexus with builds repository. How I can group my versions on folders named snapshot-x.x ?
Repository have snapshot type. User deployment have all privileges.
I run maven as mvn versions:set -DnewVersion=$VERSION and mvn clean deploy -B -Pbuild -Dbuild.version=$VERSION
My settings.xml work only releases repo ;-(
<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>
</server>
</servers>
<profiles>
<profile>
<id>build</id>
<repositories>
<repository>
<id>nexus-repo</id>
<name>Nexus repo</name>
<url>http://<MY-HOST>:8081:8081/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus-repo</id>
<name>Nexus repo </name>
<url>http://<MY-HOST>:8081/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<properties>
<altDeploymentRepository>
-DaltDeploymentRepository=builds::default::http://deployment:<MY_PASS>#<MY-HOST>:8081/content/repositories/builds
</altDeploymentRepository>
</properties>
</profile>
</profiles>
</settings>
<activeProfiles>
<activeProfile>build</activeProfile>
</activeProfiles>
I'm not sure what you are asking for? A repository has a fixed format which comprises of groupId:artifactId:version ?
There you see com/soebes/examples/j2ee is the groupId: com.soebes.examples.j2eee and than artifactId: app plus the version 1.1.2-SNAPSHOT with the underlying versions for a single SNAPSHOT

How to setup new local artifactory for maven?

I've read many questions and articles on this and tons of other sites, I still can't get this working.
I have maven configured to perform my builds, and now want to put the artifacts into a repository. I installed artifactory in tomcat, it appears to be working.
If I execute a "mvn clean install", the messages indicate that the artifacts are being uploaded to the local maven repository instead of artifactory:
[INFO] --- maven-install-plugin:2.3.1:install (default-install) # my-app ---
[INFO] Installing C:\maven_projects\my-app\my-app\target\my-app-1.0-SNAPSHOT.jar to C:\Users\Administrator\.m2\repository\com\mycompany\app\my-app\1.0
-SNAPSHOT\my-app-1.0-SNAPSHOT.jar
[INFO] Installing C:\maven_projects\my-app\my-app\pom.xml to C:\Users\Administrator\.m2\repository\com\mycompany\app\my-app\1.0-SNAPSHOT\my-app-1.0-SNAPSHOT.pom
If I execute a "mvn deploy:deploy-file, specifying the repository, the messages indicate the artifacts are being uploaded into artifactory, but they are not there:
mvn deploy:deploy-file -DrepositoryId=libs-release-local -Durl=http://localhost:8080/artifactory/libs-release-local -D
groupId=com.mycompany.app -DartifactId=my-app -Dversion=1.0-SNAPSHOT -Dpackaging=jar -Dfile=target/my-app-1.0-SNAPSHOT.jar
[...]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building my-app 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-deploy-plugin:2.7:deploy-file (default-cli) # my-app ---
Downloading: http://localhost:8080/artifactory/libs-release-local/com/mycompany/app/my-app/1.0-SNAPSHOT/maven-metadata.xml
Uploading: http://localhost:8080/artifactory/libs-release-local/com/mycompany/app/my-app/1.0-SNAPSHOT/my-app-1.0-20130202.014428-1.jar
Uploading: http://localhost:8080/artifactory/libs-release-local/com/mycompany/app/my-app/1.0-SNAPSHOT/my-app-1.0-20130202.014428-1.pom
The POM.XML file is:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>central</id>
<url>http://localhost:8080/artifactory/libs-release</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>snapshots</id>
<url>http://localhost:8080/artifactory/libs-snapshot</url>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://localhost:8080/artifactory/plugins-release</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>snapshots</id>
<url>http://localhost:8080/artifactory/plugins-snapshot</url>
<releases>
<enabled>false</enabled>
</releases>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<distributionManagement>
<repository>
<id>sademo</id>
<name>sademo-releases</name>
<url>http://localhost:8080/artifactory/ext-release-local</url>
</repository>
<snapshotRepository>
<id>sademo</id>
<name>sademo-snapshots</name>
<url>http://localhost:8080/artifactory/ext-snapshot-local</url>
</snapshotRepository>
</distributionManagement>
</project>
The settings.xml file is:
<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<servers>
<server>
<username>admin</username>
<password>password</password>
<id>sademo</id>
</server>
<server>
<username>admin</username>
<password>password</password>
<id>sademo-releases</id>
</server>
</servers>
<mirrors>
<mirror>
<mirrorOf>*</mirrorOf>
<name>remote-repos</name>
<url>http://localhost:8080/artifactory/remote-repos</url>
<id>remote-repos</id>
</mirror>
</mirrors>
<profiles>
<profile>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>sademo</id>
<name>libs-release</name>
<url>http://localhost:8080/artifactory/libs-release</url>
</repository>
<repository>
<snapshots />
<id>sademo-snapshots</id>
<name>libs-snapshot</name>
<url>http://localhost:8080/artifactory/libs-snapshot</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>plugins-release</name>
<url>http://localhost:8080/artifactory/plugins-release</url>
</pluginRepository>
<pluginRepository>
<snapshots />
<id>snapshots</id>
<name>plugins-snapshot</name>
<url>http://localhost:8080/artifactory/plugins-snapshot</url>
</pluginRepository>
</pluginRepositories>
<id>artifactory</id>
</profile>
</profiles>
<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>
</settings>
Any ideas on how I can get the "mvn clean install" to upload the jar into artifcatory?
In maven
mvn install
is intended to install the artifacts into the local repository and NOT into the remote repository.
To upload the artifacts to the remote repository you need to say:
mvn deploy
The mvn deploy will use the entries from distributionManagement to upload the artifacts to the given repository.
In your examples the pom should not contain any configurations for repositories, cause you have already done it in the settings.xml file.
Apart from that it looks that your configuration is not 100% correct, cause the message:
Uploading: http://localhost:8080/artifactory/libs-release-local/com/mycompany/app/my-app/1.0-SNAPSHOT/my-app-1.0-20130202.014428-1.jar
Uploading: http://localhost:8080/artifactory/libs-release-local/com/mycompany/app/my-app/1.0-SNAPSHOT/my-app-1.0-20130202.014428-1.pom
shows the location where the artifacts have been put into. In this case libs-release-local but the artifacts are SNAPSHOT's and not releases.
I would say to change the following:
<repository>
<snapshots />
<id>sademo-snapshots</id>
<name>libs-snapshot</name>
<url>http://localhost:8080/artifactory/libs-snapshot</url>
</repository>
into:
<repository>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>sademo-snapshots</id>
<name>libs-snapshot</name>
<url>http://localhost:8080/artifactory/libs-snapshot</url>
</repository>

Resources