Maven deploy plugin disable redeployment - maven

Is it possible to disable redeployment just from pom level via deployment plugin configuration?
Im trying to prevent redeployment of few artifacts in artifactory but dont want to set this globaly (i know it should be dole globaly, but im just a user of that artifactory and it is not up to me to decide).
Thats why i was wondering if it is posible to configure my artifacts poms to fail if deployment would in fact mean redeployment of non SNAPSHOT version.
Maven used: 3.6.1

There is no parameter for deploy:deploy to achieve this. There are two workarounds to prevent unintentional deploying at least:
1. deploy:deploy <skip>
<properties>
<skipDeploy>true</skipDeploy>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.0.0-M1</version>
<configuration>
<skip>${skipDeploy}</skip>
</configuration>
</plugin>
</plugins>
</build>
Deploy with:
mvn deploy -DskipDeploy=false
2. Deploy to local TEMP by default, use profile to really deploy
<distributionManagement>
<repository>
<uniqueVersion>false</uniqueVersion>
<id>local-dummy-repo</id>
<name>local dummy repository to prevent unintentional re-deploying</name>
<url>file://${env.TEMP}/maven-dummy-repo</url>
<layout>default</layout>
</repository>
</distributionManagement>
<profiles>
<profile>
<id>deploy</id>
<distributionManagement>
<repository>
<uniqueVersion>false</uniqueVersion>
<id>repo</id>
<name>real repository</name>
<url>scheme://authority/path</url>
<layout>default</layout>
</repository>
</distributionManagement>
</profile>
</profiles>
Deploy with:
mvn deploy -Pdeploy

Related

One maven dependency from mvnrepository.com resolves while the other does not

TLDR;
One depndency resolves and other does not. Can someone share how to debug it? or share some insight on what may be going on ?
Details:
I created a new maven project to create models and api in typescript from OpenApiV3.yaml file.
In my project's pom file I added a plugin.
<profile>
<id>typescript-angular</id>
<build>
<plugins>
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>3.0.25</version>
swagger-codegen-maven-plugin does not resolve. I get error in build that it could not be found.
<profiles>
<profile>
<id>typescript</id>
<build>
<plugins>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.1.0</version>
While openapi-generator-maven-plugin resolves. And does generate the objects.
org.openapitools openapi-generator-maven-plugin 5.1.0
io.swagger.codegen.v3 swagger-codegen-maven-plugin 3.0.25
We, in organization, do have a local nexus deployment but aparently this behavior is with same pluginRepositories in project's pom file. No change done to make it work for the other dependency.
<pluginRepositories>
<pluginRepository>
<id>maven-repository</id>
<name>Maven Repository</name>
<url>https://mvnrepository.com/artifact/</url>
</pluginRepository>
<pluginRepository>
<id>maven-central</id>
<name>Maven Central</name>
<url>https://repo1.maven.org/maven2/</url>
</pluginRepository>
</pluginRepositories>
Can someone share how to debug it? or share some insight on what may be going on ?

Generate and update changelog.md after mvn release:perform

I would like to generate, update changelog.md and commit to Bitbucket repository after mvn release:perform is done.
In angular, it has #semantic-release/git, #semantic-release/commit-analyzer, #semantic-release/release-notes-generator, #semantic-release/npm, #semantic-release/changelog, #semantic-release/exec. Is there anything similar in maven release?
pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>3.0.0-M1</version>
<configuration>
<tagNameFormat>v#{project.version}</tagNameFormat>
<checkModificationExcludes>
<checkModificationExclude>pom.xml</checkModificationExclude>
</checkModificationExcludes>
</configuration>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>release</id>
<url>https://nexus.../.../release/</url>
</repository>
</distributionManagement>
<properties>
<project.scm.id>my-scm-server</project.scm.id>
</properties>
<scm>
<connection>scm:git:https://user#bitbucket.org/user/comutils.git</connection>
<developerConnection>scm:git:https://user#bitbucket.org/user/comutils.git</developerConnection>
<tag>HEAD</tag>
</scm>
You can use maven-semantic-release which will generate release notes using Angular style commit messages for Maven projects in the same way as you would do with npm projects.
The documentation suggests how to publish to Maven Central, but you can save some hassle by publishing to Github packages.

sonar-maven-plugin 3.7.0.1746

I am getting below error while using the plugin (sonar-maven-plugin 3.7.0.1746):
ERROR:
Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project kcc-xbu-saprfc-services-sys-api: Unexpected internal error near index 1
I have added below in pom.xml file in respective sections:
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.7.0.1746</version>
</plugin>
<dependency>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.7.0.1746</version>
</dependency>
<repository>
<id>org.sonarsource.scanner.maven</id>
<name>sonar-maven-plugin</name>
<url>https://mvnrepository.com/artifact/org.sonarsource.scanner.maven/sonar-maven-plugin</url>
<layout>default</layout>
</repository>
<pluginRepository>
<id>org.sonarsource.scanner.maven</id>
<name>sonar-maven-plugin</name>
<layout>default</layout>
<url>https://mvnrepository.com/artifact/org.sonarsource.scanner.maven/sonar-maven-plugin</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
Versions currently being used:
SonarQube version: 7.9.1
MULE_EE with version 4.2.2
JDK: 1.8.0_251 (mixed mode)
Maven Version : 3.173.0
However maven is getting executed from "C:\Program Files\Maven\apache-maven-3.6.2\bin\mvn.cmd".
I am executing the build using azure pipeline.
Please let me know how to resolve this issue. Thank you.
If you are going to submit your code for SonarQube platform, normally the pom file doesn't need to have those dependencies, instead of it you can decouple that in changing the settings.xml of the maven (if you have a dedicated server, it should be inside .m2 folder for Windows).
Maven's settings.xml should have this profile:
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
<properties>
<sonar.login>*your-user-here*</sonar.login>
<sonar.password>*your-pwd-here*</sonar.password>
<sonar.host.url>*url-of-your-sonar-platform*</sonar.host.url>
</properties>
</activation>
<profile>
After that, you can setup you pipeline to run the following command for your project:
mvn sonar:sonar
Good luck!

Can't find Maven artifact in Sonatype's repos

I see my published dependency here:
https://oss.sonatype.org/#nexus-search;quick~ores
it looks like this is the staging repo? Because when I search here:
https://search.maven.org/search?q=ores
I get no results:
My guess is that I publishing to staging not prod when I publish the artifact, anybody know how to publish to production using Sonatype?
In my pom.xml file I have:
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
and I have:
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.8</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>false</autoReleaseAfterClose>
</configuration>
</plugin>
So perhaps I need to be using the production plugins instead of staging?
Seems tricky. When I set
<autoReleaseAfterClose>true</autoReleaseAfterClose>
I get this error:
[ERROR] Failed to execute goal
org.sonatype.plugins:nexus-staging-maven-plugin:1.6.8:deploy
(injected-nexus-deploy) on project async.0.1: Execution
injected-nexus-deploy of goal
org.sonatype.plugins:nexus-staging-maven-plugin:1.6.8:deploy failed:
403 - Forbidden -> [Help 1]

How do I include a Maven plugin from a local repository?

I have a custom plugin that compresses files that I need to include in my maven build. So I have included this plugin in my pom.xml:
<build>
// Other tags
<plugin>
<groupId>someGroupId</groupId>
<artifactId>somePlugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Since it is a custom plugin, it is not available in any public Maven repository. So whenever I try to build, I get an error message saying:
Failed to read artifact .....
even though I have added it to my local repository. How can I refer to this plugin that is in my local repository?
If you mean local repository in the classic sense, make sure that you installed your plugin jar correctly. Install it to your local repository again with the following command:
mvn install:install-file -Dfile=/some/path/somePlugin.jar -DgroupId=someGroupId -DartifactId=somePlugin -Dversion=1.0.0 -Dpackaging=jar -DgeneratePom=true -DcreateChecksum=true
You should then be able to use your plugin in your Maven build.
If you mean local in the sense of some locally hosted repository, you need to specify the repository containing your artifact as a pluginRepository. Add the following to the top level of your pom.xml:
<pluginRepositories>
<pluginRepository>
<id>some-repo</id>
<name>Some Repository</name>
<url>http://some.host/some/path</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

Resources