Cannot build multi-module Maven project with Azure Pipelines - azure

I'm trying to build a Maven project using Azure Pipelines, but I'm having troubles with it, as for some reason the Maven#3 task seems to be unable to resolve some dependencies.
The project is structured as follows
Desk
|---- desk-api
| \---- pom.xml
|---- desk-implementation
| \---- pom.xml
\---- pom.xml
Room
|---- room-api
| \---- pom.xml
|---- room-implementation
| \---- pom.xml
\---- pom.xml
User
|---- user-api
| \---- pom.xml
|---- user-implementation
| \---- pom.xml
\---- pom.xml
where
desk-implementation depends on both user-api and desk-api
room-implementation depends on both user-api and room-api
user-implementation depends on every API
the "external" POMs for each service merely invoke the POMs of the related service implementation and API.
Using Maven#3 task I'm able to build the JARs for the APIs correctly (they're also put under .m2/repository folder).
However, whenever I try to build an implementation it fails. It seems the agent, when executing the task, cannot find the previously built JARs for the APIs.
This also happens when trying to build the service as a whole (this because it invokes the POM related to its implementation, but fails as previously explained).
I tried to copy the JARs into $(System.DefaultWorkingDirectory) and into each implementation folder, but again those JARs were not found.
I checked the permissions and they're fine and so are the goals I use when building.
Looking for some answers, it seems that the only way to solve this issue is by using Azure Artifacts and modifying the POMs accordingly.
I find it very weird: some colleagues of mine (working on the same Maven project, but using Jenkins instead of Azure Pipelines) manage to build it beautifully.
Is it really not possible to build a multi-module Maven project in Azure Pipelines without using Azure Artifacts?

Related

How do I get the sources jar from jitpack repository?

I am using jitpack to make resolve my java projects dependencies for projects on github.
I have set my maven pom.xml to build a sources jar in the project and I can see from the log-file on jitpack.io, that the sources-jar is being build. But when I include the project, the sources-jar does not appear in my local repository.
I need the sources jar for better code completion in IntelliJ.
Anyone has an idea about what I am doing wrong?
Snippet from jitpack log file that shows that the sources jar file is generated by jitpack:
✅ Build artifacts:
com.github.abstractica-org:JavaCSG:Refactor-d59d2a4908-1
Files:
com/github/abstractica-org/JavaCSG/Refactor-d59d2a4908-1
com/github/abstractica-org/JavaCSG/Refactor-d59d2a4908-1/JavaCSG-Refactor-d59d2a4908-1-sources.jar
com/github/abstractica-org/JavaCSG/Refactor-d59d2a4908-1/JavaCSG-Refactor-d59d2a4908-1-sources.jar.md5
com/github/abstractica-org/JavaCSG/Refactor-d59d2a4908-1/JavaCSG-Refactor-d59d2a4908-1-sources.jar.sha1
com/github/abstractica-org/JavaCSG/Refactor-d59d2a4908-1/JavaCSG-Refactor-d59d2a4908-1.jar
com/github/abstractica-org/JavaCSG/Refactor-d59d2a4908-1/JavaCSG-Refactor-d59d2a4908-1.jar.md5
com/github/abstractica-org/JavaCSG/Refactor-d59d2a4908-1/JavaCSG-Refactor-d59d2a4908-1.jar.sha1
com/github/abstractica-org/JavaCSG/Refactor-d59d2a4908-1/JavaCSG-Refactor-d59d2a4908-1.pom
com/github/abstractica-org/JavaCSG/Refactor-d59d2a4908-1/JavaCSG-Refactor-d59d2a4908-1.pom.md5
com/github/abstractica-org/JavaCSG/Refactor-d59d2a4908-1/JavaCSG-Refactor-d59d2a4908-1.pom.sha1
com/github/abstractica-org/JavaCSG/Refactor-d59d2a4908-1/build.log
So the file IS created on jitpack.io but it never makes it to my local maven repository...
I am using jitpack to use the project from another project and everythings works fine except that I do not get the sources jar file in my local maven repository, only the main jar.
Here is the part of the pom.xml that includes the project from another project:
<dependencies>
<dependency>
<groupId>com.github.abstractica-org</groupId>
<artifactId>JavaCSG</artifactId>
<!--suppress MavenModelInspection -->
<version>Refactor-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>

How to migrate the artifacts of a maven project which has a parent artifact into Azure Artifacts?

I'm trying to migrate the artifacts of a maven project from Sonatype Nexus to Azure Artifacts and I'm following the steps described here.
So it's basically
mvn clean install: Creates a local copy of the artifacts.
Change the repository and distribution management URL and point to the destination Azure feed url.
mvn deploy: Deploys the artifacts into Azure feed.
This must work. But the project that I'm working on has a parent, which is provided to us externally and is not in maven central. That parent is not getting deployed and is missing from Azure Artifact feed and is resulting in an error.
Sample pom.xml
<project xmlns....>
<parent>
<groupId>parent.pom..
..
</parent>
<groupId>main.project...
<name>project..
<version>x.x..
<packaging>pom..
....
....
</project>
Getting error on trying to build the project from Azure Artifact.
C:/...MainProject> mvn clean install
...
...
[ERROR][ERROR] Some problems were encountered while processing the POMs
[FATAL] Non-resolvable parent POM for main.project...: Could not transfer the artifact parent.pom
Tried to create a small project with only parent pom as dependency and tried to upload it Azure Artifact feed.
But a similar error is being thrown up.
According to your description, please check if there is a proxy in your internet.
And try to delete the .m2 local Directory and run mvn clean install again to check if it works.
You can refer to this answer.

How to create a build pipeline for multi-module maven in Azure Devops

I have a multi-module maven project in azure repo:
Parent
----App
--POM.xml
----Core
--POM.xml
----API
--POM.xml
----ParentPOM.xml
When I tried to build App project in Azure, I am getting the following error: [ERROR] Failed to execute goal on the project: Could not resolve dependencies for project com.core:jar:1.0: Could not find artifact com.core:jar:1.0 in central (https://repo.maven.apache.org/maven2).
So I tried to create multiple tasks in the same azure build to package for each module (App, Core, API), which also gives the same result. Could someone please help me on how to build the multi-module project and get the App jar file.
The way I've done it:
with this command: install -pl (module name) -am
where the module name should be one of the submodules. If you want to build all of them then only go with install
I have found the solution for the multi-module maven dependency issue, First We need to build the parent pom.xml, then build the submodules as per hierarchical order. In between each module, add a task to copy and move the jar files to the staging directory. Here shared the image of my build steps. Please take a look and comment on any questions.
Please look into the DevOps configuration for reference

Build and include JSF taglib as jar in a Dynamic Web Project using Maven

I am working on a JSF taglib. To test it I compile it to a JAR as described here and add it manually to a Dynamic Web Project (In the WEB-INF/lib directory).
I know that this step can be automated, but I do not know how. Can anybody explain how to copy a generated jar to a second project in Eclipse?
Thanks in advance!
quite some steps to do :)
add a pom.xml into your project and follow the maven directory structure. use packaging "jar" for the taglib project. Lets assume you use groupId=com.company.taglib artifactId=company-taglib version=1.0.0-SNAPSHOT
if you do a mvn install on this project it will copy the jar into your local maven repository (usually found at ~/.m2/ - now maven can resolve the dependency on your local machine
add a pom.xml to your webproject, use packaging "war" and add the taglib project as a dependency (within <dependencies> in pom.xml).
<dependency>
<groupId>com.company.taglib</groupId>
<artifactId>company-taglib</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
Maven will resolve this dependency from your local repository. In Eclipse using the m2e Plugin it will resolve the project directly.
To "publish" the taglib.jar you need an infrastructure to share artifacts. Usually using a repository proxy (Sonatype Nexus or Artifactory). You can also use a network folder using the file:// protocol for quick startup.
In the pom.xml you need to add the <distributionManagement> section (in the taglib pom.xml) to specify the folder / proxy the artifacts are uploaded to. A mvn deploy will then build and copy the jar file for you.
Other developers need to add that location as repository in settings.xml (I dont recommend doing that in pom.xml) or if you setup a maven proxy configure a mirrorOf in settings.xml
There are archteypes available (project templates) that will help you creating initial project structures: http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
see also: http://maven.apache.org/guides/getting-started/index.html

How host local repository in pom.xml

When ever i tried to Goals >> Compile pom.xml, I am getting the following error.
An internal error was encountered invoking the maven goal: Please check the exception details.
org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException: Missing:
1) org.apache.httpcomponents:httpcore:jar:4.1.2
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=org.apache.httpcomponents -DartifactId=httpcore -Dversion=4.1.2 -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.apache.httpcomponents -DartifactId=httpcore -Dversion=4.1.2 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
Path to dependency:
1) org.apache.httpcomponents:httpcore:jar:4.1.2
1 required artifacts are missing.
As per above error it suggests, Alternatively, if you host your own repository you can deploy the file there.
how can i provide a local repository to pom.xml.
This article explains what you require. Quoting from it:
A maven repository is just a directory somewhere, and that’s about it. In order to use it there are very few steps you need to do.
Choose a directory
Make sure its accessible via some network protocol to everyone who needs it (i.e. serve it via http or ftp or something.
Put the libraries you need in the directory, in a specific format.
Set up your maven builds to read from the repository
(optional) set up your maven builds to deploy your repository
To put existing libraries into the repository, use the maven deploy command.
To set up your build to read from the repository add the following xml to your pom.xml file:
servername-download
description
https://host/path
A detailed article for complete understanding of Maven repositories
Are you sure your Maven setup works? The artifact you're looking for is in the public Maven repository:
http://repo1.maven.org/maven2/org/apache/httpcomponents/httpcore/4.1.2/
It should be found just like any other publicly available artifact. Please check the spelling of the artifact and group in your pom file to make sure that you don't have a typo.
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.1.2</version>
</dependency>
What does Maven print before it fails? It usually says where it's checking for the artifact - does the URL I posted above show up?
Do you see similar issues with other artifacts?
You shouldn't have to host this artifact yourself since it's publicly available. It looks like you're running Maven from an IDE - can you try to run it from command line to see if you get the same error there?
To host local repository in pom.xml we have to set up maven properly.
we need to modify settings.xml and provide the local repository path in maven packages and then used it with IDE. So now on words if JAR is not available in my local repository then and then only maven tries to search in its maven repository.
please follow below blog to configure maven properly.
http://chiragsdiary.blogspot.in/2013/02/cxf-webservice-example-step-by-step.html

Resources