Maven packaging: mvn deploy using .zip rather than .rar - maven

I'm deploying from a Jenkins job, using the Maven "deploy" target, to an Archiva repository.
Currently I'm not using other targets and I create the pom.xml just in order to pack and deploy the files.
My pom.xml 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>group_continuous</groupId>
<artifactId>MyArtifactId</artifactId>
<version>60-r12345-v0.0.01</version>
<packaging>rar</packaging>
<distributionManagement>
<repository>
<id>repo_continuous</id>
<name>Continuous</name>
<url>http://10.142.255.179:8080/repository/repo_continuous/</url>
</repository>
</distributionManagement>
</project>
In order to have it work I just put all the required files in the folder
target/MyArtifactId-60-r12345-v0.0.01/*
before calling
mvn deploy
I know that I can use for the purpose the command
mvn deploy:deploy-file
And use a plugin to just create the .zip archive but I wonder if there's a way to just add the .zip support in order to have the exact same functionality of the .rar

Related

POM for my own repo is missing, no dependency information available

I am currently learning software development and working on an assignment based on using a release from one project in another using jitpack.
The first project, which I want to add as a dependency in my second, simply has three classes and a JUnit test for each. I changed several things so I am at V5.0 release now.
https://github.com/MohamedMoustafaNUIG/assignment1/releases/tag/V5.0
My second project is not yet pushed, but this is the pom file:
<?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>com.nuig</groupId>
<artifactId>assignment1_driver</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.github.MohamedMoustafaNUIG</groupId>
<artifactId>assignment1</artifactId>
<version>v5.0</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
</project>
When I try to build with dependencies (in netbeans), I get this error:
Failed to execute goal on project assignment1_driver:
Could not resolve dependencies for project com.nuig:assignment1_driver:jar:1.0-SNAPSHOT:
Failure to find com.github.MohamedMoustafaNUIG:assignment1:jar:v5.0 in
https://jitpack.io was cached in the local repository,
resolution will not be reattempted until the update interval of jitpack.io has
elapsed or updates are forced -> [Help 1]
I also get this warning:
The POM for com.github.MohamedMoustafaNUIG:assignment1:jar:v5.0 is missing, no dependency information available
Even though the zip file (from linked release) has the pom file.
Any help appreciated as I have no idea how to resolve this the issue
You either need to:
build assignment1 on the same machine with clean install to make it available in the local repository.
deploy assignment1 to a Maven repository with clean deploy and then use this as a <repository>.

pom.xml with Jitpack loads wrong version of dependency

I am using JitPack to share a private Github release that I manage.
I have uploaded a new release version to github successfully - when I download it as jar from Github, I see the correct files.
But when I use pom.xml to download it as a dependency via the pom.xml file, it downloads an earlier release version.
I ran mvn dependency:list to see what is actually being downloaded and it says that the correct version is the one being downloaded.
[INFO] com.github.myGroupId:my-artifact-id:jar:THE_CORRECT_VERSION:compile
But when I browse in the jar classes I see that it is still the old version.
The solutions I tried so far:
-submitting another new release
-cleaning my maven local repository
All didn't work. I still get the old version.
The pom.xml code:
<?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>com.shai.test</groupId>
<artifactId>sandbox</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.github.myGroupId</groupId>
<artifactId>my-artifact-id</artifactId>
<version>MY_LATEST_VERSION</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
</project>

Multi Project Maven and AWS CodeBuild

I am new to Maven, and i am working on a project that have one or more dependencies on my other projects.
Example: I have 3 maven projects.
MyProject
MyProjectOther
MyProjectCommon
Both MyProject and MyProjectOther are independent of each other and do not have much to do with each other, but they both have a dependency on MyProjectCommon. (MyProjectOther dose not matter much to this question, just included it to show that MyProjectCommon is used in other projects)
Locally i can make this work, i have a workspace where i have both packages. I understand this is because Maven stores MyProjectCommon in a local repository.
Both projects (MyProject and MyProjectCommon) have their own GitHub repository, and my AWS CodeBuild is directed to build the MyProject repository. This fails as MyProjectCommon dose not exists for AWS CodeBuild.
How can i get this build to work with AWS CodeBuild, getting CodeBuild to download and build MyProjectCommon before it builds MyProject?
MyProject pom.xml
<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">
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<modelVersion>4.0.0</modelVersion>
<groupId>com.myproject</groupId>
<artifactId>myproject</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>myproject</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>com.myproject</groupId>
<artifactId>myproject.common</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>
MyProjectCommon pom.xml
<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">
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<modelVersion>4.0.0</modelVersion>
<groupId>com.myproject</groupId>
<artifactId>myproject.common</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>myproject.common</name>
<url>http://maven.apache.org</url>
</project>
Unfortunately there is no easy way of doing this on any CI system that does not understand how underlying build dependencies are resolved and/or have 'always consistent' cached artifacts.
You do have couple of options here though. First option is to publish your artifact from the library build. You'll in this case have to setup multiple projects in CodeBuild, one for MyProject and other for MyProjectCommon. Builds for MyProjectCommon would publish artifacts to S3 (codebuild can do this) and then builds for MyProject can download the published artifact from S3 (you can also replace S3 with maven repositories but you'll have to publish the artifacts).
Other more saner option is to use maven modules to solve this issue (maven reactor) and create single repository for MyProjectCommon and MyProject. Essentially your projects end up under same repository and are built in the dependency order as specified in the pom of individual projects. Here's more documentation on the maven modules https://maven.apache.org/guides/mini/guide-multiple-modules.html
In the example you have, you'll still keep the pom file for MyProject and MyProjectCommon, but create another parent pom that defines both MyProject and MyProjectCommon as modules. You can then create CodeBuild project for this repository and run for example 'mvn install' which will compile both MyProjectCommon and MyProject in dependency order. You'll have an option to publish multiple artifacts from your build in CodeBuild or single zip with artifacts for both MyProject and MyProjectCommon.
I hope this helps.

Apply a Variable or Profile to a Downloaded Parent Pom

I have a Pom.xml that downloads a Parent Pom for it's <distributionmanagement> from. I am trying to have where the project deploys to be dependent upon a variable within the Parent Pom. Below is my Parent Pom:
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>dev</groupId>
<artifactId>company-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<distributionManagement>
<repository>
<id>Artifactory</id>
<name>Artifactory-releases</name>
<url>http://artifactory:8081/artifactory/${repo}</url>
</repository>
<snapshotRepository>
<id>Artifactory</id>
<name>Artifactory-snapshots</name>
<url>http://artifactory:8081/artifactory/${repo}</url>
</snapshotRepository>
</distributionManagement>
</project>
When I run a mvn deploy I use the command line mvn deploy -Drepo=integration but it does not work. The deploy just places the project in dev and not integration like the variable says to. The parent pom is hosted on artifactory so I believe that because it is downloaded during the deploy the variable isn't being applied to it.

Install artifacts from artifactory to local repository

I have an artifactory which stores artifacts, this is a given pom:
<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.test.test2.test3</groupId>
<artifactId>web-gen</artifactId>
<version>v2.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Test dynamic web layer</name>
</project>
How can I install the given artifact to my local repository?
mvn install, mvn install:file and others can't help. Pretty frustrated about it...
The simplest solution would be to use it as a dependency which will automatically download the artifact and put it into your local repository.
Otherwise you can use the maven-dependency-plugin by using the get goal:
mvn dependency:get -DartifactId=WhatEver -DgroupId=XX -Dversion=xxx -Dclassfier=..

Resources