Setup Maven to use our dedicated server - maven

We would like to maintain our own repository server that is totally cut-off from the Internet because of our company policies.
To achieve this, we install Maven in our system and executed the following command to force Maven to download all the dependencies for offline purpose:
mvn dependency:go-offline
Upon completion, we move all the downloaded dependencies into our Tomcat server and update maven's settings.xml to mirror to a URL served by Tomcat (where all the dependencies are stored). We are not using 3rd party repository manager for now.
<mirror>
<id>ProjectsCentralRepository</id>
<mirrorOf>*</mirrorOf>
<name>Central Repository</name>
<url>http://localhost:8080/repos</url>
</mirror>
Problem occurs when we remove all the dependencies in our .m2\repository and try to run "mvn package" to package a simple project that does not have any dependencies (refers to our pom.xml). Many of the dependencies were downloaded successfully from our server but we do not understand why the following error occurs. Weren't all the dependencies downloaded already when we execute mvn dependency:go-offline?
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.6:resources (default-resources) on project test: Execution default-resources of goal org.apache.maven.plugins:maven-resources-plugin:2.6:resources failed: Plugin org.apache.maven.plugins:maven-resources-plugin:2.6 or on
e of its dependencies could not be resolved: The following artifacts could not be resolved: org.apache.maven:maven-profile:jar:2.0.6, org.apache.maven:maven-repository-metadata:jar:2.0.6, org.apache.maven:maven-plugin-registry:jar:2.0.6, classworlds:classworlds:jar:1.1-alpha-2: Could not find artifa
ct org.apache.maven:maven-profile:jar:2.0.6 in ProjectsCentralRepository (http://localhost:8080/repos) -> [Help 1]
[ERROR]
I also notice Maven had downloaded multiple versions of different dependencies. For example, it had downloaded 2.05 to 2.2.0 of the maven-profile POM files but only 2.0.9 has the jar file. How do I force maven to download only the latest version of Maven dependencies and to use the latest version when performing "mvn package" goal?
Thank you guys.
Our 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>xx.yyyy.Test</groupId>
<artifactId>test</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>Testing</name>
<url>http://maven.apache.org</url>
</project>

Related

mvn Deployment failed: repository element was not specified in the POM

When I run mvn clean deploy on my project I get an error
Also my project in eclipse displays the following errors which I don't know if they are related to my current problem.
Project configuration not up-to-date with pom.xml
plugin configuration not covered by lifecycle configuration
In addition my eclipse doesn't seems to compile the files correctly. My SpringBoot java files aren't being compiled as java files. I can tell because if I deliberately induce syntax errors, there isn't a compilation error. This is all run on eclipse EE and is part of a maven project so I don't even know if a source folder is needed.
Also I'm displaying my main pom.xml file below and it has compilation errors on "pom" and both "&ndash"
I've tried the following solutions
Eclipse Blue, Maven: Project configuration is not up-to-date with pom.xml
Failed to resolve version for org.apache.maven.archetypes
repository element was not specified in the POM inside distributionManagement element or in -DaltDep loymentRepository=id::layout::url parameter
<?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.fanniemae.dfc</groupId>
<artifactId>dfc_app</artifactId>
<packaging>pom</packaging>
<version>0.0.1-SNAPSHOT</version>
<modules>
<module>dfc_angular</module>
<module>dfc_springBoot</module>
</modules>
<!--<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3RELEASE</version>
<relativePath/> <!– lookup parent from repository
–>
</parent>-->
</project>
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project dfc_app: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter
mvn deploy will deploy the produced artifact to a Maven Repository.
To do so it needs the configuration to which repository it must be deployed and this is missing.
But I assume that you don't want to deploy it to a repository but just build it.
That's mvn install This will install it in your local repository.
Maybe you should start with reading the docs: https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html

Issue in adding third party dependency in Maven during Jenkins build - ODM

I am trying to build ODM projects outside of eclipse using the Jenkins pipeline and Maven plugin. I am following the link : https://www.ibm.com/support/knowledgecenter/en/SSQP76_8.9.0/com.ibm.odm.dserver.rules.designer.run/build_topics/con_buildcmd_intro.html
Though this link works well without the Jenkins pipeline in my local(Windows), but when I try to run the same setup in Jenkins(Linux machine), I am getting the following error :
[WARNING] The POM for com.ibm.rules.buildcommand:rules-compiler-maven-plugin:jar:8.10.0.0 is missing, no dependency information available
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. # helloWorld:hello-xom:[unknown-version], /var/lib/jenkins/workspace/odm-devops-build/Hello XOM/pom.xml, line 19, column 21
[ERROR] Unresolveable build extension: Plugin com.ibm.rules.buildcommand:rules-compiler-maven-plugin:8.10.0.0 or one of its dependencies could not be resolved: Failure to find com.ibm.rules.buildcommand:rules-compiler-maven-plugin:jar:8.10.0.0 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced #
[ERROR] Unknown packaging: decisionservice # helloWorld:hello-main:[unknown-version], /var/lib/jenkins/workspace/odm-devops-build/Hello Main Service/pom.xml, line 14, column 16
The pom file which is referred in the above error is as below:
<?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>
<parent>
<groupId>helloWorld</groupId>
<artifactId>parent</artifactId>
<version>1.0.0</version>
<relativePath>..</relativePath>
</parent>
<artifactId>hello-main</artifactId>
<packaging>decisionservice</packaging>
<build>
<plugins>
<plugin>
<groupId>com.ibm.rules.buildcommand</groupId>
<artifactId>rules-compiler-maven-plugin</artifactId>
<configuration>
<deployments>
<deployment>
<name>simple dep</name>
</deployment>
</deployments>
<resolvers>
<resolver>
<!-- The values of the kind and url of the project correspond to the 'kind' and 'url' attribute values of an 'entries' element in the .ruleproject file. -->
<kind>JAVA_PROJECT</kind>
<url>platform:/Hello XOM</url>
<!-- The artifactKey references the groupId and artifactId of a Maven dependency. -->
<artifactKey>${project.groupId}:hello-xom</artifactKey>
</resolver>
</resolvers>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>hello-xom</artifactId>
<type>jar</type>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Please let me know if anyone has faced a similar issue or has a possible resolution to the above issue.
Thanks in advance.
Possible resolution: "install the Build Command Maven plugin and its related Operational Decision Manager artifacts in your Maven repository" ... "on each machine that contains build agents"
To deploy the Build Command Maven plugin to a remote Maven repository, you must configure Maven in your environment. You then use the following command: mvn deploy:deploy-file -Dfile=rules-compiler-maven-plugin.jar -DpomFile=rules-compiler-maven-plugin.pom
This requires access to the Jenkins / Maven server, and at many companies would be done by DevOps.
You install the Build Command Maven plugin and its related Operational Decision Manager artifacts in your Maven repository.
Deploying the Build Command plugin
You deploy the plugin only once on each machine that contains build agents.
To deploy the Build Command Maven plugin to a remote Maven repository, you must first configure Maven in your environment.
Then, in <InstallDir>/buildcommand/rules-compiler, open a command prompt.
Use the following command:
mvn deploy:deploy-file -Dfile=rules-compiler.jar -DpomFile=rules-compiler-maven-plugin.pom
If you do not have a remote repository, you can test the plugin locally. You run the following command:
mvn install:install-file -Dfile=rules-compiler.jar -DpomFile=rules-compiler-maven-plugin.pom
This command adds the following plugin in your local Maven repository:
com/ibm/rules/buildcommand/rules-compiler
 Deploying the annotations archive
If you want to build COBOL projects or projects that use XOM annotations, you must also deploy the annotations archive to your environment before you can build the projects.
In <InstallDir>/buildcommand/rules-compiler, open a command prompt.
Use the following command:
mvn deploy:deploy-file -Dfile=rules-compiler.jar -DpomFile=xom-annotations.pom
If you do not have a remote repository, you can test the plugin locally. You run the following command:
mvn install:install-file -Dfile=rules-compiler.jar -DpomFile=xom-annotations.pom
This command adds the following plugin in your local Maven repository:
com/ibm/rules/buildcommand/xom-annotation
Source

Why does "mvn dependency:tree" list one version, but "mvn clean install" try to download another version?

I've got a Maven (3.2.5) project which is failing due to a missing dependency. The relevant part of the mvn clean install output:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5:single (package-jar-with-dependencies) on project splitter: Failed to create assembly: Failed to resolve dependencies for project: groupId1:splitter:jar:2.12.3: Missing:
[ERROR] ----------
[ERROR] 1) groupId2:location-service:jar:2.12.3
However, mvn depdency:tree claims that the 2.12.3 version is not necessary:
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # splitter ---
[INFO] groupId1:splitter:jar:2.12.3
[INFO] +- groupId2:location-service:jar:2.12.1:compile
There is no other location-service dependency listed.
The pom.xml explicitly calls out the 2.12.1 dependency:
<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>
<parent>
<groupId>groupId2</groupId>
<artifactId>artifactId</artifactId>
<version>2.12.0</version>
</parent>
...
<groupId>groupId1</groupId>
<artifactId>splitter</artifactId>
<packaging>jar</packaging>
<version>2.12.3</version>
<name>splitter</name>
<url>http://maven.apache.org</url>
...
<dependencies>
<dependency>
<groupId>groupId2</groupId>
<artifactId>location-service</artifactId>
<version>2.12.1</version>
</dependency>
...
Interestingly, the parent pom.xml is not available in this directory structure (the person that created the SVN branch branched a portion of the repository that didn't include the parent pom.xml). However, Maven does not complain about it missing, so it's getting it from my~/.m2/repository directory.
Sorry reputation seekers, yet again I found the solution to my question while composing it. But it's complicated enough to go ahead and post the question and answer, in case anyone else runs into a similar problem.
The problem turned out to be that the parent pom.xml in my ~/.m2/repository directory set the location-service dependency to ${project.version}. Apparently this was enough for the maven-assembly-plugin to want to download it, despite the explicit dependency in the module pom.xml. This is a bug in maven-assembly-plugin:2.2-beta-5. Neither the module nor the parent pom.xml name an explicit version of the maven-assembly-plugin. I haven't the foggiest idea why maven is selecting the 2.2-beta-5 version to download, as it isn't even close to the latest version. mvn dependency:tree -Dverbose doesn't even mention maven-assembly-plugin. Explicitly using maven-assembly-plugin:2.5.5 solves the problem.

Install remote maven artifact to local repository

I would like to install an artifact from maven central repository to my local repository. Can anyone help me on getting this? With other words, I want some jars from maven central repositories to be downloaded into my local repository, but using maven, not going in browser and downloading needed jar files.
I am not entirely sure why would you want artifacts from maven for reasons other than using them in a maven based project... But since that's what you want:
Maven installs artifacts locally when they are used - that is when you install a project that has them in dependencies. Therefore the simplest solution would be to create a dummy project, put the artifacts you want as dependencies and install it. Something like:
<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>dummy</groupId>
<artifactId>dummy</artifactId>
<version>dummy</version>
<dependencies>
<-- artifacts you want -->
</dependencies>
</project>
within pom.xml file in an empty folder. It will additionally create a dummy artifact in your local repository you might want to get rid of manually if it bothers you.

Plugin is not being found after I install it in local repo

I have written a plugin and to install it in the local repository I run the command :
mvn install
The plugin is successfully added to my local maven repository but when I run :
com.tools:generate:0.0.1-SNAPSHOT:generatepom
I receive the error :
plugin com.tools:generate:0.0.1-SNAPSHOT or one of its dependencies
could not be resolved: Failed to read artifact descriptor for
com.tools:generate:jar:0.0.1-SNAPSHOT: Failure to find
com.tools:generate:pom:0.0.1-SNAPSHOT in
https://nexus.mydomain.com:8181/prod/content/groups/level0/ was cached
in the local repository, resolution will not be reattempted until the
update interval of nexuspro-level0 has elapsed or updates are forced
-> [Help 1]
It seems to be searching for the plugin on Nexus even though the plugin is installed locally. How can I configure maven to run the plugin in the local repository ?
Here is the build & beginning of 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tools</groupId>
<artifactId>generate</artifactId>
<packaging>maven-plugin</packaging>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>com.tools</groupId>
<artifactId>generate</artifactId>
<version>0.0.1-SNAPSHOT</version>
<configuration>
<repositoryUri>http://repository.sonatype.org/service/local/lucene/search?sha1=</repositoryUri>
</configuration>
</plugin>
</plugins>
</build>
most likely your plugin's pom contains different identification (groupId,artifactId,version).
Also, make sure that you specified maven-plugin there.
If it is not the case, please provide plugin's pom excerpt, or its build log excerpt (the "istalling ..." part).
You can read about developing plugins here.
I would suggest to turn your approach around and deploy the plugin to the remote repository.
If that is not desired it should however work fine. You might be running into a problem with your Maven repository meta data. I would try to run
mvn -U com.tools:generate:0.0.1-SNAPSHOT:generatepom
forcing an update as a next step.

Resources