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

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

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

Specify version when deploying to nexus from maven

I've forked Confluent's Kafka Connect HDFS writer and now I'd like to deploy a version of this jar to my local Nexus.
mvn clean deploy Works like a charm and deploys the jar.
https://[nexus]/repository/releases/io/confluent/kafka-connect-hdfs/5.0.0/kafka-connect-hdfs-5.0.0.jar
So far so good, but to make a distinction between the confluent versions and my own deployment I'd like to change the version of the build to something like 5.0.0-1 or so (preferably the tag name when pushed, but that's step 2)
The pom.xml is basically the same as the 5.0.0-post release, but here the most important parts:
<parent>
<groupId>io.confluent</groupId>
<artifactId>kafka-connect-storage-common-parent</artifactId>
<version>5.0.0</version>
</parent>
<artifactId>kafka-connect-hdfs</artifactId>
<packaging>jar</packaging>
<name>kafka-connect-hdfs</name>
<organization>
<name>Confluent, Inc.</name>
<url>http://confluent.io</url>
</organization>
<url>http://confluent.io</url>
<description>
A Kafka Connect HDFS connector for copying data between Kafka and Hadoop HDFS.
</description>
...
<dependencies>
...
<dependency>
<groupId>io.confluent</groupId>
<artifactId>kafka-connect-storage-common</artifactId>
<version>${confluent.version}</version>
</dependency>
<dependency>
<groupId>io.confluent</groupId>
<artifactId>kafka-connect-storage-core</artifactId>
<version>${confluent.version}</version>
</dependency>
...
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.confluent</groupId>
<version>0.10.0</version>
<artifactId>kafka-connect-maven-plugin</artifactId>
...
So first I added <version> tags to the pom.xml, but it started using that as the default for all confluent.version and complained that it couldn't find for example: https://[nexus]/repository/releases/io/confluent/kafka-connect-storage-hive/5.0.0-1/kafka-connect-storage-hive-5.0.0-1.pom
Next I tried the versions plugin from maven
mvn versions:set -DnewVersion=5.0.0-1 clean deploy
But that complained about the parent:
[ERROR] Failed to execute goal org.codehaus.mojo:versions-maven-plugin:2.7:set (default-cli) on project kafka-connect-hdfs: Project version is inherited from parent. -> [Help 1]
I don't even care if the version is 5.0.0 in the code, I just wat to deploy to a different version in our artifactory.
I'm not a maven expert, so maybe I'm missing some very basic clue, but all help is welcome.
So there were some good suggestions, but in the end the one thing that worked best for me in our setup was to use the deploy:deploy-file command for maven.
mvn deploy:deploy-file \
-Dfile=target/kafka-connect-hdfs-5.0.0.jar \
-DrepositoryId=[nexus id] \
-Durl=[nexus url] \
-Dversion=$TAG \
-DgroupId=io.confluent \
-DartifactId=kafka-connect-hdfs
The major downside was that I had to respecify parameters that were already present in the pom.xml (artifactId, groupId, ect), but it works, and that's what counts :-)
You can specify the version with ${revision} parameter.
To do this, you need to add <version> tag with this variable in pom.xml:
<artifactId>kafka-connect-hdfs</artifactId>
<version>5.0.0-${revision}</version>
<packaging>jar</packaging>
And then provide it to the maven command. E.g.,
mvn clean package -Drevision=01 will generate kafka-connect-hdfs-5.0.0-01.jar file.

Setup Maven to use our dedicated server

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>

How to release and reference Grails plugins using local Maven repository

Summary
I create two plugins A and B with Grails 2.3.4 where B is a plugin used by A plugin. I get error when I use A plugin in my application.
Details
When I run the following command, for plugin B, it successfully release the plugin to local maven repository. I can see it in the ~/.m2/... folder.
~plugin-b: grails maven-install
Then I add a reference to plugin B with plugin A, so I add the reference to BuildConfig in plugin A:
plugins {
compile "com.test.plugins:b:1.0.0-SNAPSHOT"
}
Now, I think, I should be able to run the next command and the plugin should be released to the local maven repository but I get the error instead:
~plugin-a: grails maven-install
| Plugin packaged grails-a-1.0.0-SNAPSHOT.zip
| Generating POM file.....
| Error Could not find artifact com.test.plugins:b:jar:1.0.0-SNAPSHOT (scope: compile) (Use --stacktrace to see the full trace)
| POM generated: //dependencies/dependencies_A_plugin/target/pom.xml...
Maven install complete.
Here is the generated POM file:
// pom header
<artifactId>a</artifactId>
<packaging>zip</packaging>
<version>1.0.0-SNAPSHOT</version>
<name>A</name>
<description>Brief summary/description of the plugin.
</description>
<url>http://grails.org/plugin/a</url>
<developers>
<developer>
<name>Your name</name>
</developer>
</developers>
<dependencies>
<dependency>
<groupId>com.test.plugins</groupId>
<artifactId>b</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
... just ending tags
Actually, also plugin A has been released to the local Maven repository, but it is probably corrupted, because when I create a Grails application and add a reference to A plugin into BuildConfig, then I am not even able to start up that application.
~ grails
| Error Resolve error obtaining dependencies: Could not find artifact com.test.plugins:b:jar:1.0.0-SNAPSHOT (Use --stacktrace to see the full trace)
| Error Could not find artifact com.test.plugins:b:jar:1.0.0-SNAPSHOT
So, the application has found A plugin, but not the B plugin, which is referenced by A plugin. To me, it seems there is an issue with generated POM file in the local Maven repository for the A plugin. There is probably missing:
<type>zip</type>
But I have not found a way how to add the type to that dependency.
Anyone able to help?

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