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

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>

Related

Problems setting up dokka in Maven

I have added the following to my pom.xml, based on this page:
https://github.com/Kotlin/dokka#using-the-maven-plugin
pom.xml
<dependency>
<groupId>org.jetbrains.dokka</groupId>
<artifactId>dokka-maven-plugin</artifactId>
<version>0.9.19-dev-15</version>
</dependency>
<pluginRepositories>
<pluginRepository>
<id>jcenter</id>
<name>JCenter</name>
<url>https://jcenter.bintray.com/</url>
</pluginRepository>
</pluginRepositories>
<plugin>
<groupId>org.jetbrains.dokka</groupId>
<artifactId>dokka-maven-plugin</artifactId>
<version>0.9.19-dev-15</version>
<executions>
<execution>
<phase>pre-site</phase>
<goals>
<goal>dokka</goal>
</goals>
</execution>
</executions>
<configuration>
<dokkaPlugins>
<plugin>
<groupId>org.jetbrains.dokka</groupId>
<artifactId>kotlin-as-java-plugin</artifactId>
<version>0.9.19-dev-15</version>
</plugin>
</dokkaPlugins>
</configuration>
</plugin>
When I run the project, I get the following errors:
Dependency 'org.jetbrains.dokka:dokka-maven-plugin:0.9.19-dev-15' not found
Plugin 'org.jetbrains.dokka:dokka-maven-plugin:0.9.19-dev-15' not found
Can someone help out with this configuration? Thanks in advance.
For this version add the Kotlin Dev Maven repository to you project:
<repositories>
<repository>
<id>k-dev</id>
<name>K-dev</name>
<url>https://dl.bintray.com/kotlin/kotlin-dev/</url>
</repository>
</repositories>
You can see the URL of the repository for this library page on the Maven central:
Note: this artifact is located at Kotlin Dev repository (https://dl.bintray.com/kotlin/kotlin-dev/)

Maven deploy plugin disable redeployment

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

Not able to download Jars from nexus

I have project A which is dependency of project B. Since project B should get latest jar version of Project A . I purge Project A jar from local so Project B will get Project A jar from nexus since it has been deleted from local.
I can see in the logs that It can download jar from nexus . but still getting pom for jar is missing
below are the logs
Downloading from : ://10.245.240.43:8081/nexus/repository/maven-snapshots/com/sgl/smartpra/master/model/smartpra-master-model/0.0.1-SNAPSHOT/smartpra-master-model-0.0.1-20191126.094645-53.jar
[INFO] Downloaded from : ://10.245.240.43:8081/nexus/repository/maven-snapshots/com/sgl/smartpra/master/model/smartpra-master-model/0.0.1-SNAPSHOT/smartpra-master-model-0.0.1-20191126.094645-53.jar (183 kB at 1.7 MB/s)
The POM for com.sgl.smartpra.master.model:smartpra-master-model:jar:0.0.1-20191126.094645-53 is missing, no dependency information available
You can see that it can able to pull jars from nexus still getting artifact missing.
I added maven plugin to perge dependent jars from local so it will pull latest jar from nexus
refer Below snippet
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>purge-local-dependencies</id>
<phase>process-sources</phase>
<goals>
<goal>purge-local-repository</goal>
</goals>
<configuration>
<includes>
<include>com.sgl.smartpra.global.master.model:smartpra-global-master-model</include>
<include>com.sgl.smartpra.batch.global.model:smartpra-batch-global-model</include>
<include>com.sgl.smartpra.master.model:smartpra-master-model</include>
<include>com.sgl.smartpra.exception.txn.model:smartpra-exception-txn-model</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
Below is nexus repository configuration for downloading jars from nexus
Please check below code
refer Below snippet
I have project A which is dependency of project B. Since project B should get latest jar version of Project A . I purge Project A jar from local so Project B will get Project A jar from nexus since it has been deleted from local.
<repositories>
<repository>
<id>maven-group</id>
<url>**strong text**/10.245.240.43:8081/nexus/repository/maven-group/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>

maven does not change the snapshot jar file in local repository

We config jfrog artifactory successfully and create a pom.xml to build and deploy our basic jar files into it as snapshot. then we configure another project to get those jar files from repository and it did successfully too, then we try to change basic libraries and deploy it again as the same snapshot name, and it did correctly but when we want to get those libraries again, maven does not change the basic libraries in local repository, unless we change the version of the snapshot but we don't want to do it.
deploy pom.xml configuration file
<plugin>
<groupId>org.jfrog.buildinfo</groupId>
<artifactId>artifactory-maven-plugin</artifactId>
<version>2.2.2</version>
<inherited>false</inherited>
<executions>
<execution>
<id>build-info</id>
<goals>
<goal>publish</goal>
</goals>
<configuration>
<deployProperties>
<gradle>awesome</gradle>
</deployProperties>
<artifactory>
<includeEnvVars>true</includeEnvVars>
<timeoutSec>60</timeoutSec>
<propertiesFile>publish.properties</propertiesFile>
</artifactory>
<publisher>
<contextUrl>{{ARTIFACTORY_CONTEXT_URL|"http://tls.local:9081/artifactory"}}</contextUrl>
<username>admin</username>
<password>AP5PqkrxgwKVMBeY6wxPYr66R3M</password>
<excludePatterns>*-tests.jar</excludePatterns>
<repoKey>libs-release-local</repoKey>
<snapshotRepoKey>libs-snapshot-local</snapshotRepoKey>
</publisher>
<buildInfo>
<buildName>plugin-demo</buildName>
<buildNumber>{{DRONE_BUILD_NUMBER|TRAVIS_BUILD_NUMBER|CI_BUILD_NUMBER|BUILD_NUMBER}}
</buildNumber>
<buildUrl>{{DRONE_BUILD_URL|CI_BUILD_URL|BUILD_URL}}</buildUrl>
</buildInfo>
<licenses>
<autoDiscover>true</autoDiscover>
<includePublishedArtifacts>false</includePublishedArtifacts>
<runChecks>true</runChecks>
<scopes>compile,runtime</scopes>
<violationRecipients>build#organisation.com</violationRecipients>
</licenses>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
</configuration>
</plugin>
third party pom.xml configuration file:
<repository>
<id>snapshots</id>
<name>libs-snapshot</name>
<url>http://tls.local:9081/artifactory/libs-snapshot</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
How can we achieve our goal?
first we must configure our jfrog repository's maven snapshot version behavior to unique and check handle releases and handle snapshot and then delete completely our local repository's snapshot

Maven Include dependencies in Executable Jar

Am new to Maven...
Trying to create a simple applet.
Include dependencies for the applet.
For this I have tried :
<repository>
<id>lib</id>
<name>lib</name>
<releases>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>file://${project.basedir}/lib</url>
</repository>
I have these files included in the lib folder under my project structure.
this lib contains couple of jar files and a JNI dll which I need to use in my applet.
Is there any better option to create repository than the above,Kindly share?
Packaging applet jar with dependencies.
For this I have tried :
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
I expect the above to wrap my dependencies into one single jar, but its not been the case.
the generated jar file size doesnt contain the dependency jar files.(I can say coz the size of the jar file remains unchanged for both jars with and without dependencies are same)
Am I in the right way of doing things with Maven?
Take look at shade plugin, this plugin creates executable "uber jar" or if you realy need something really complicated assembly plugin.

Resources