Maven fails to get SNAPSHOT builds from repository - java

Our internal repository (Artifactory) now contains both the stable builds as well as SNAPSHOT versions of our internal libraries.
For stable builds there has never been a problem of downloading anything from the repository.
However, when I add a -SNAPSHOT, Maven claims to be unable to find the dependency, even though it is most definitely in the repository.
If I build and deploy the dependency locally (i.e. into my local repo) all works normally.
Basically, this works:
<dependency>
<groupId>com.example</groupId>
<artifactId>ourlibrary</artifactId>
<version>1.0.0</version>
</dependency>
and this doesn't:
<dependency>
<groupId>com.example</groupId>
<artifactId>ourlibrary</artifactId>
<version>1.0.1-SNAPSHOT</version>
</dependency>
Even though both versions were built the same way and deployed (as far as I can possibly tell) correctly to the repository.
The error:
Missing:
----------
1) com.example:ourlibrary:jar:1.0.1-SNAPSHOT,
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=com.example -DartifactId=ourlibrary -Dversion=1.0.1-SNAPSHOT, -Dpackaging=jar -Dfile=/path/to/file
Alternatively, if you host your own repository you can deploy the file there:
mvn deploy:deploy-file -DgroupId=com.example -DartifactId=ourlibrary -Dversion=1.0.1-SNAPSHOT, -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
Path to dependency:
1) com.example:product:war:2.0.0-SNAPSHOT
2) com.example:ourlibrary:jar:1.0.1-SNAPSHOT,
While this sounds similar to this question, the resolution arrived at there does not apply to my case.
Any insights into this issue would be greatly appreciated.
Edit
Running with -X (as John V. suggested) revealed the following:
[DEBUG] Skipping disabled repository central
[DEBUG] ourlibrary: using locally installed snapshot
[DEBUG] Skipping disabled repository central
[DEBUG] Using mirror: http://repo.example.com/repo (id: repo.example.com)
[DEBUG] Artifact not found - using stub model: Unable to download the artifact from any repository
com.example:ourlibrary:pom:1.0.1-SNAPSHOT
from the specified remote repositories:
repo.example.com (http://repo.example.com/repo)
[DEBUG] Using defaults for missing POM com.example:ourlibrary:pom:1.0.1-SNAPSHOT:compile
[DEBUG] com.example:ourlibrary:jar:1.0.1-SNAPSHOT:compile (selected for compile)

Two thoughts come to mind:
The path structure in your internal
repository for your artifact is
incorrect. I suggest running the
maven command with -X parameter. It
will display the maven's attempt at
downloading the files. Get the line
that has your repository as the url
and try and look for it yourself.
The path should look like
/com/example/ourlibrary/1.0.1/ourlibrary-1.0.1-SNAPSHOT.jar
You didnt include your repository as
a repository in your pom.xml

Typically you have a separate snapshots url from releases url. Just different paths in the same repository, but listed as separate repositories in the pom. The one for snapshots needs to have snapshots enabled, and the one for releases has snapshots disabled:
<repositories>
<repository>
<id>central</id>
<url>
http://<releases-url>
</url>
**<snapshots>
<enabled>false</enabled>
</snapshots>**
</repository>
<repository>
<id>snapshots</id>
<url>
http://<snapshots-url>
</url>
<snapshots>
**<enabled>true</enabled>**
<!-- never, daily, interval:X (where X is in minutes) or always -->
<!--<updatePolicy>daily</updatePolicy> -->
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>

Related

How to make maven download dependencies from central repo. rather than downloading from remote company repo.?

So I thought of creating a spring boot project but on my company laptop. I downloaded the project from spring initializer and tried to execute on IntelliJ idea but got this error:
"java: package org.springframework.boot does not exist"
"java: cannot find symbol
symbol: class SpringBootApplication"
I ran maven clean and install cmds but still the same issue. Now I reckon this is happening bc maven is downloading dependencies from my remote company repository.
I remember saving a custom setting.xml file in .m2 folder which contains a custom repository.
So if I am right how can I make maven download from the central repo or solve this problem?
It sounds like you listed your own repository in your POM or settings.xml, like so:
<repositories>
<repository>
<id>vaadin-addons</id>
<url>https://maven.vaadin.com/vaadin-addons</url>
</repository>
</repositories>
Doing so, without also listing Maven Central, will cause Maven to only attempt to resolve from your own repository. You must also list Maven Central, like so:
<repositories>
<repository>
<id>vaadin-addons</id>
<url>https://maven.vaadin.com/vaadin-addons</url>
</repository>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2/</url>
</repository>
</repositories>
Maven checks repositories in the order they are specified. You cannot specify a repository per dependency, but you could create a new module with your dependencies and their specific repositories.

How do I add Maven dependencies to Azure Pipelines

I am attempting to build a Maven Build Pipeline in Azure Devops.
I have one project that has files shared across several others (as set of micro service projects), so the maven compile for that project creates a .jar file ( which is added to my local maven repository .m2) when I do the build on my laptop. We can call it shared.jar for now.
​
Then when I compile the micro services on my laptop, they each have a dependency on the jar file in my .m2 repo. And they pick up the dependency from there and the Maven build (mvn clean install).
​
Unfortunately, The code build pipeline does not maintain a local .m2 repo. So when I try to do a “mvn clean install” on each micro service they cannot locate shared.jar, so the build fails.
​
I have been able to successfully add the .jar file to a Feed and Artifact under Azure DevOps, but I can't seem to figure out how to pull it into the Micro Services Build.
HOW do I pick up the dependency for a local jar file in my CI/CD Maven build pipeline and get it into a maven repo that my build will find?
I have attempted to follow this link: https://learn.microsoft.com/en-us/azure/devops/artifacts/get-started-maven?view=azure-devops
We do this by having a separate azure pipeline to build the dependency which deploys it to an Azure feed:
variables:
- name: mavenRepoURL
value: 'https://myorg.pkgs.visualstudio.com/myproject/_packaging/myfeed/maven/v1'
- task: DownloadSecureFile#1
name: mvnSettings
displayName: 'Download Maven settings'
inputs:
secureFile: 'maven-azuredevops-settings.xml'
- task: MavenAuthenticate#0
displayName: Maven Authenticate Artifacts
inputs:
artifactsFeeds: 'myfeed'
- task: Maven#3
inputs:
mavenPomFile: 'pom.xml'
options: '-X -B -s $(mvnSettings.secureFilePath) -DWHERE="AzureDevops" -DremoteRepositories=$(mavenRepoUrl) clean deploy -U'
mavenAuthenticateFeed: true
publishJUnitResults: true
testResultsFiles: '**/TEST-*.xml'
Note that its important that your personal access token is not stored in version control for security reasons hence the complication of having to upload it as a secure file and download it in the pipeline.
The dependency is added to the pom for the project using it as normal but with the Azure feed configured as well
<dependency>
<groupId>com.foobar.blah</groupId>
<artifactId>artifactId</artifactId>
<version>2.0.2</version>
</dependency>
<profile>
<id>AzureDevops</id>
<activation>
<property>
<name>WHERE</name>
<value>AzureDevops</value>
</property>
</activation>
<properties>
</properties>
<distributionManagement>
<repository>
<id>myfeedname</id>
<url>https://myorg.pkgs.visualstudio.com/_packaging/myfeed/maven/v1</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</distributionManagement>
</profile>
Caveat: I am not that familiar with maven or Azure so some things may not be right. For example, I have issues with project rather than organisation scoped feeds. See What are the equivalent maven commands and settings to upload and download azure artifacts?
I just had to do this myself to create a docker image whit the final .jar and got inspired by Bruce Adams answer and the documentation about maven
you have to add to your pipeline.yml
- task: DownloadSecureFile#1
name: mvnSettings
displayName: 'Download Maven settings'
inputs:
secureFile: 'maven-azuredevops-settings.xml'
- task: MavenAuthenticate#0
displayName: Maven Authenticate Artifacts
inputs:
artifactsFeeds: 'yourFeed'
- task: Maven#3
inputs:
mavenPomFile: 'pom.xml'
goals: 'deploy'
options: '-s $(mvnSettings.secureFilePath)'
mavenAuthenticateFeed: true
publishJUnitResults: true
testResultsFiles: '**/TEST-*.xml'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.11'
mavenVersionOption: 'Default'
and in your pom.xml you need to add the configuration to connect to your artifacts feed
<repositories>
<repository>
<id>yourFeed</id>
<url>https://yourOrganization.pkgs.visualstudio.com/yourProject/_packaging/yourFeed/maven/v1</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>bithaus</id>
<url>https://yourOrganization.pkgs.visualstudio.com/yourProject/_packaging/yourFeed/maven/v1</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</distributionManagement>
and create the file setting.xml on your {user.home}/.m2/ folder, and upload it to the secure files on your pipeline.
Hope it helps someone.
please check following itemes:
Make sure that when you run "mvn clean install" command, maven read
configurations from settings.xml file in ${user.home}/.m2 .
Check id, username and password whitin <server></server> tags.
Please before running "mvn clean install" remove all files and
folder in .m2 folder.
enable debugging option when run maven install command by add -X or
--debug options.

Maven Build Jar

I am working on Maven project and I have a jar app-client.jar which have dependency on app-core.jar. So I have a pom.xml for app-client.jar and that pom.xml has dependency of app-core so we added dependency of app-core in this pom.xml.
Now I wanna use the app-client.jar in my main project. Because this jar is build locally and not available at remote repository. So I did add the app-client and also specify the location repository where it will located.
as following..
<repositories>
<repository>
<id>repo</id>
<releases>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>file://${project.basedir}/../lib</url>
</repository>
<repositories>
<dependencies>
<dependency>
<groupId>com.sample</groupId>
<artifactId>app-client</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
and also I put my jar as following
[My Module] / [com] / [sample] /[app-client] /[1.0]/app-client-1.0.jar
When I run mvn clean install I got error app-client's pom.xml not found. and build get failed. Usually when I use single jar then its working fine, but if I use jar having dependency with other jar it getting failed.
So how can I build my app-client jar and their pom so that it behave normal and also deploy app-core.jar too.
firstly when you are building app-client.jar build a fat jar which includes app-core.jar dependency.
Next copying app-client-1.0.jar into the specified location of local repo doesn't work, to add this jar into your local repo use this command mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>.
If you build app-client.jar with mvn clean install, then it will be installed into your Maven local repository (.../.m2/repository). Then any other project on the same computer can reference it in its pom without further information. So no <repositories> entry necessary.
If you want to work with multiple people on the same project, use a Nexus/Artifactory server to share the jars.
Solutions with lib folders and system paths are deprecated and cause trouble.

spring roo build fails because of missing dependency org.springframework.build.aws.maven

I just cloned a fresh copy of spring-roo from github and tried to mvn install it. But that failed because a dependency was missing.
I suspect the solution to work for other cases of missing build in spring projects as well.
Missing:
----------
1) org.springframework.build.aws:org.springframework.build.aws.maven:jar:3.1.0.RELEASE
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=org.springframework.build.aws -DartifactId=org.springframework.build.aws.maven -Dversion=3.1.0.RELEASE -Dpackaging=jar -Dfile=/path/to/file
Alternatively, if you host your own repository you can deploy the file there:
mvn deploy:deploy-file -DgroupId=org.springframework.build.aws -DartifactId=org.springframework.build.aws.maven -Dversion=3.1.0.RELEASE -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
Path to dependency:
1) org.springframework.roo:org.springframework.roo.root:pom:1.2.5.BUILD-SNAPSHOT
2) org.springframework.build.aws:org.springframework.build.aws.maven:jar:3.1.0.RELEASE
I could solve this problem by adding the spring releases repository to the pom.xml of spring-roo.
...
<repositories>
...
<repository>
<id>repository.springframework.maven.release</id>
<name>Spring Framework Maven Release Repository</name>
<url>http://maven.springframework.org/release</url>
</repository>
</repositories>
...

Maven: metadata xml files downloaded often from remote repositories

I'm using Maven to handle a Java project. I thought that Internet connectivity was only needed in the 1st compile to download the required libraries from the remote repositories, but I get several download messages whenever I compile code. Messages like these:
Downloading: http://repo.maven.apache.org/maven2/org/eclipse/core/resources/maven-metadata.xml
Downloading: http://repository.springsource.com/maven/bundles/external/org/eclipse/core/resources/maven-metadata.xml
Downloading: http://repository.springsource.com/maven/bundles/release/org/eclipse/core/resources/maven-metadata.xml
Downloading: https://oss.sonatype.org/content/repositories/snapshots/org/eclipse/core/resources/maven-metadata.xml
Why that happens and how I could prevent it?
This usually happens when no version information is specified for the artifact.
maven-metadata.xml is a file which contains the <groupId>, <artifactId> and the versioning information about the various versions available for the dependency.
If the version of the artifact is not specified in the pom.xml, maven downloads this metadata file to check if the local repository contains the latest version.
So, you can avoid this download by specifying the version information of the artifact in pom.xml file, instead of changing the update policy which might affect the update process of other jar files in future.
The most important thing is to start using a repository manager furthermore check the configuration in your settings.xml file which can be configured to check the remote repositories (update policy).
1) Check that you indeed have these artifacts in your local repo
2) Check your repository configuration so you are using your repos only to download releases.
<project>
...
<repositories>
<repository>
<id>my-repo1</id>
<name>your custom repo</name>
<url>http://jarsm2.dyndns.dk</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
...
</project>
3) You can force maven to only use your local repo with the -o option:
mvn -o clean package

Categories