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

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

Related

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.

Nothing will be added to build artifact 'drop'

I am trying to host a jave project. I have build the pipeline by setting up the parameters as shown in the images but the i am encountering the error saying ##[warning]Directory '/home/azureuser/myagent/.\run.cmd/5/a' is empty. Nothing will be added to build artifact 'drop'. How do I fix this?
It seems you want to publish your jar package to build artifact 'drop'. Jar package should be in the $(System.DefaultWorkingDirectory)\target folder. Thus, you need to use the copy file task to copy jar package from target folder, then publish the package to drop.
You could also check the log of Maven task to see the specific location of jar package.

Unable to pass user.dir parameter to code using pom.xml and mvn cmdline

Im a newbie to azure and maven. I have created a build pipeline and it is dropping artifacts to Build.ArtifactDirectory. In CD pipeline, there is a java class which uses System.getProperty("user.dir"). But this path is taking wrongly and it throws ClassNotFoundException.
Reason for this:
Actual artifacts in cd after drop is present in path: C:/agent1/1/a/buildpipeline/drop/s/TestCode/src/main/read.java
user.dir : is searching in path: C:/agent1/1/a/ in which the code is not available.
Fix the issue:
To fix this, i need to manually pass the user.dir value through maven commandline that is -Duser.dir="pathname". But this is not working
I can change the artifact drop path from build pipeline and include a task of download artifact in release pipeline - Is not working because, I need to add a maven task to integrate pom.xml and it is automatically showing the path C:/agent1/1/a/buildpipeline/drop/s/TestCode/pom.xml.
Please help me with a solution

How can I deploy spark artifacts to a custom maven repository?

I have a fork of apache spark on github that I build from.
I have a maven repository that our company uses to manage dependencies.
Suppose the url of this maven repository is https://xyz.abc.com/maven.
If I run a command like
./build/mvn -Pyarn -Phadoop-2.6 -Dhadoop.version=2.6.5 -DskipTests install
Then all the jars get deployed to my local maven repository, but what I would really like is for them to be deployed to the repository mentioned above.
How can I do that? Do I need to modify certain files or set environment variables? Do I need to add a credential file somewhere?
I also looked into doing it with sbt, but I could not figure out how to do it with that either.
You want to publish artifact build by maven to remote repository (https://xyz.abc.com/maven).
Take a look at this guide for required configuration.

GitHub project deployment failed on azure

I want to deploy my .Net project from GitHub repository to the azure server.
In Deployment options I am getting Building failed error.
Here are screen shots of my Deployment details and Logs
1- Deployment Details:
2- Activity Log:
According to your description and logs, I found you have error in MSbuild step.
The error shows some files not found in your project. I suggest you could exclude the related files in the csproj file or make sure the related files is in your project.
Besides, I suggest you could firstly clone the project to your local and test it , make sure the project could build well without any error then publish to the GitHub and deploy to the azure.
Update:
I also write a test demo on my computer and I reproduce your error.
Error image:
I think in your project you have inclued the bin and obj folder into your project and then you push the project to the github.
Like below:
After you push the project to the github, the csporj file will include all the bin and obj references.
Like below:
This is the reason about your MSBuild fail.
So I suggest you uninclude all the bin and obj folder in the local and push to the github again. Then it will work well.
Azure looks in your site/repository/packages folder for all the packages your app uses. By looking through it you will find that visual studio doesn't deploy all of the files from your local packages folder to the azure one. MSBuild needs these files when you push to git and trigger a build. Ftp into your azure site and look for the packages folder. Upload every missing file (dll) from your local folder to the azure one. This worked for me and now I can trigger a build and deployment from bitbucket to azure app service upon a push.
Additionally, if you have other projects in your VS solution and you are using VS to build those projects and then put the dll into your main projects bin folder, that will cause a missing file error also. I create a folder in my packages folder and link the dll to my main folder from there. That way when you perform the fix above, the file needed by your main project is in the packages folder also.
I hope this helps!

Resources