Retrieve all jars from Local jfrog Repository using Maven - maven

I am hosting a Local Repository with 80+ Jar files which are related to our internal Project
Something like this
I want to add a tag in my Maven pom.xml where in I retrieve all the jar files in one shot when I create a new project in Eclipse.
These jars are static and will not change.
Can anyone please help in setting up this?
In Artifactory - "Set me Up", I can see this TAG, but its for pushing a final jar

You have at least two options:
1. Use a parent pom
Add all the 80 dependencies to a POM which looks like this:
<?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>your.company</groupId>
<artifactId>ourDependencies</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging> <!-- IMPORTANT -->
<dependencies>
<!-- place here 80 dependencies -->
<dependency>
...
</dependency>
</dependencies>
<build> <!-- optional -->
<plugins>
<plugin>
...
</plugin>
</plugins>
</build>
<distributionManagement>
... <!-- optional -->
</distributionManagement>
</project>
In the project that needs the dependencies, add a <parent> element to the pom.xml:
<project>
<groupId>your.company</groupId>
<artifactId>newApplication</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging> <!-- or war or ... -->
....
<parent>
<groupId>your.company</groupId>
<artifactId>ourDependencies</artifactId>
<version>1.0.0</version>
</parent>
...
</project>
Keep in mind that every project can have only one parent.
2. Create an archetype
This way is more complex. You can create a simple project similar to "HelloWorld" which contains all the dependencies. Based on this project, you can create an archetype which serves as a template when you create a new Maven project.
More Informations:
Introduction to archetypes
archetype tutorial

Related

OpenLiberty Maven Plugin

I am trying to create a runnale openliberty server as part of my release process. I have a a multi module maven project with a submodule dedicated to packaging the server as a runnable. When I do a mvn clean package a lovely executable jar is produced which bundles one of the other submodules (war). The problem I am facing is when I do a maven deploy to our asset repo the packaged server is being uploaded as a zip file rather than a jar file. Does anyone know how to get the deploy plugin to upload the jar?
Here is a sample pom file
<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>
<parent>
<groupId>au.com.xxxx.xxxx</groupId>
<artifactId>xxx-backend-parent</artifactId>
<version>0.0.16-SNAPSHOT</version>
</parent>
<artifactId>xxxx-openliberty-server</artifactId>
<packaging>liberty-assembly</packaging>
<name>fusion-openliberty-server</name>
<description>Runnable Jar containing xxxxand the OpenLiberty applictaion server</description>
<dependencies>
<!-- Package xxxx-application.war with server assembly -->
<dependency>
<groupId>au.com.xxx.xxx</groupId>
<artifactId>xxxx-application</artifactId>
<version>${project.version}</version>
<type>war</type>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Enable liberty-maven-plugin -->
<plugin>
<groupId>net.wasdev.wlp.maven.plugins</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>2.6.1</version>
<extensions>true</extensions>
<configuration>
<assemblyArtifact>
<groupId>io.openliberty</groupId>
<artifactId>openliberty-javaee8</artifactId>
<version>18.0.0.3</version>
<type>zip</type>
</assemblyArtifact>
<include>runnable</include>
<serverName>xxx</serverName>
<appsDirectory>apps</appsDirectory>
<serverEnv>${basedir}/src/main/resources/server.env</serverEnv>
<configFile>${basedir}/src/main/resources/server.xml</configFile>
<jvmOptionsFile>${basedir}/src/main/resources/jvm.options</jvmOptionsFile>
<bootstrapProperties>
<app.context.root>xxx-app</app.context.root>
<default.http.port>5000</default.http.port>
<default.https.port>5443</default.https.port>
</bootstrapProperties>
</configuration>
</plugin>
</plugins>
</build>
</project>
I don't have an answer to your question but an explanation why this happens. Every packaging type (jar, war, liberty-assembly) defines a fixed extension for the artifact(s) it creates. The liberty-assembly types defines zip as it extension. This extension is used by the maven-install-plugin and maven-deploy-plugin regardless how the local file is names. I did quite some code digging but couldn't find a way to change this. It's probably sth. that only liberty-maven-plugin can change/fix.

Read custom version config property from a property file and access it in pom.xml

I am working with maven projects . I want to read my version number from a property file and access this version variable into my pom.xml instead of updating each time in the 17.3-SNAPSHOT in the pom.xml . So when i want to update my version in a particular development sprint,the change should have only in the version number property in the property file and will be able to build jar file with the updated version . So I want to create a version config variable in an external property file
(example : /main/resources/version_config.properties) and access this in pom.xml for the build process .
<dependency>
<group Id>x.x.x</group Id>
<artifact Id>maven-model</artifact Id>
<version>2.0</version>
</dependency>
instead of using the above version value(2.0) between version tag , i want to get this value from a property file names xxx.properties (property like , version.config.value=2.0)
I tried the above solutions .Can any one help on on this ?
I suggest you to define the version of your application in a specific Maven project that you can use as parent Maven project.
From Maven documentation "Introduction to the POM" (Example 5) :
Example 5
The Scenario
Given the previous original artifact POMs again,
com.mycompany.app:my-app:1's POM
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
</project>
com.mycompany.app:my-module:1's POM
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-module</artifactId>
<version>1</version>
</project>
and this directory structure
.
|-- my-module
| `-- pom.xml
`-- parent
`-- pom.xml
The Solution
To do both project inheritance and aggregation, you only have to apply
all three rules.
com.mycompany.app:my-app:1's POM
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<packaging>pom</packaging>
<modules>
<module>../my-module</module>
</modules>
</project>
com.mycompany.app:my-module:1's POM
<project>
<parent>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>my-module</artifactId>
</project>
NOTE: Profile inheritance the same inheritance strategy as used for the POM itself.

Jenkins and Maven

see Project Structure I am trying to deploy my SOA project using Jenkins and Maven.
while deployment I am getting below error. Can some one please help me with this.
while using only maven command I am able to deploy this project on SOA server. I am getting error only when I try to deploy project using Jenkins.
Started by user Atul Gupta
Building in workspace C:\Users\atulgupt\.jenkins\workspace\sca-test
Checking out a fresh workspace because there's no workspace at C:\Users\---\.jenkins\workspace\sca-test
Cleaning local Directory .
Checking out ----/BPEL/Trunk/test-soa-application at revision '2016-09-14T15:34:08.345 +0530'
Parsing POMs
**Failed to transfer Could not find artifact com.oracle.soa:sar-common:pom:12.2.1-0-0 in central (http://repo.maven.apache.org/maven2)
ERROR: Failed to parse POMs
org.apache.maven.project.ProjectBuildingException**: **Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM: Could not find artifact com.oracle.soa:sar-common:pom:12.2.1-0-0 in central (http://repo.maven.apache.org/maven2) and** 'parent.relativePath' points at no local POM # line 21, column 13
Parent POM:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.my.test</groupId>
<artifactId>test-soa-application</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<!-- Add project modules -->
<module>test-soa-project</module>
</modules>
</project>
Project POM.xml:-
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.my.test</groupId>
<artifactId>test-soa-project</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>sar</packaging>
<!--
This POM was generated from the SOA Maven Archetype.
Comments in this POM guide you how to use it with your project.
This POM relates to this SOA Composite, i.e. the one in this same directory.
There is another POM in the SOA Application directory (up one) which handles
the whold SOA Application, which may contain additional projects.
The parent points to the common SOA parent POM. That is a special POM that is
shipped by Oracle as a point of customization (only). You can add default values
for properties like serverUrl, etc. to the SOA common parent POM, so that you
do not have to specify them over and over in every project POM.
-->
<parent>
<groupId>com.oracle.soa</groupId>
<artifactId>sar-common</artifactId>
<version>12.2.1-0-0</version>
<relativePath></relativePath>
</parent>
<properties>
<!-- these parameters are used by the compile goal -->
<scac.input.dir>${project.basedir}/SOA/</scac.input.dir>
<scac.output.dir>${project.basedir}/target</scac.output.dir>
<scac.input>${scac.input.dir}/composite.xml</scac.input>
<scac.output>${scac.output.dir}/out.xml</scac.output>
<scac.error>${scac.output.dir}/error.txt</scac.error>
<scac.displayLevel>1</scac.displayLevel>
<!-- if you are using a config plan, uncomment the following line and update to point
to your config plan -->
<!--<configplan>${scac.input.dir}/configplan.xml</configplan>-->
<!-- these parameters are used by the deploy and undeploy goals -->
<composite.name>${project.artifactId}</composite.name>
<composite.revision>${project.version}</composite.revision>
<composite.partition>default</composite.partition>
<serverUrl>http://localhost:7071</serverUrl>
<user>atulgupt</user>
<password>july#2016</password>
<overwrite>true</overwrite>
<forceDefault>true</forceDefault>
<regenerateRulebase>false</regenerateRulebase>
<keepInstancesOnRedeploy>false</keepInstancesOnRedeploy>
<!-- these parameters are used by the test goal -->
<!-- if you are using the sca-test (test) goal, you need to uncomment the following
line and point it to your jndi.properties file. -->
<!--<jndi.properties.input>${basedir}/jndi.properties</jndi.properties.input>-->
<scatest.result>${scac.output.dir}/testResult</scatest.result>
<!-- input is the name of the composite to run test suties against -->
<input>test-soa-project</input>
<oracleHome>
${env.ORACLE_HOME}
</oracleHome>
</properties>
<!--
These refer to the properties defined above. You should probably not need to make
any changes beflow this point - these just point to the properties above.
-->
<build>
<plugins>
<plugin>
<groupId>com.oracle.soa.plugin</groupId>
<artifactId>oracle-soa-plugin</artifactId>
<version>12.2.1-0-0</version>
<configuration>
<compositeName>test-soa-project</compositeName>
<composite>${scac.input}</composite>
<sarLocation>${scac.output.dir}/sca_${project.artifactId}_rev${version}.jar</sarLocation>
<serverUrl>${serverUrl}</serverUrl>
<!-- note: compositeRevision is needed to package, revision is needed to undeploy -->
<compositeRevision>${composite.revision}</compositeRevision>
<revision>${composite.revision}</revision>
<scacInputDir>${scac.input.dir}</scacInputDir>
<!-- Uncomment the appHome property if your composite
depends on MDS. -->
<!--<appHome>${project.basedir}/..</appHome>-->
<!-- If you have a composite which contains a component that
depends on MDS (eg. Human Task, Business Rule) AND you
want to use a file-based MDS repository, then you
need to do either:
1. update the .adf/META-INF/adf-config.xml to point to
the correct location of the file based repository, i.e.
remove the reference to ${soa.oracle.home} in that file, or
2. define oracleHome and soaOracleHome here and leave the adf-config.xml file
as is. Note that the correct value for soaOracleHome is the path to
your SOA Quickstart or JDeveloper install directory,
with "/soa" appended to it.
-->
<!--<oracleHome>JDEV_HOME</oracleHome>-->
<!--<soaOracleHome>JDEV_HOME/soa</soaOracleHome>-->
<input>${input}</input>
</configuration>
<!-- extensions=true is needed to use the custom sar packaging type -->
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>com.oracle.adf.plugin</groupId>
<artifactId>ojdeploy</artifactId>
<version>12.2.1-0-0</version>
<configuration>
<ojdeploy>
${oracleHome}/jdeveloper/jdev/bin/ojdeploy.exe
</ojdeploy>
<workspace>
${basedir}/../test-soa-application.jws
</workspace>
<project>
test-soa-project
</project>
<profile>
test-soa-project
</profile>
<outputfile>
${project.build.directory}/${project.build.finalName}.jar
</outputfile>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

TeamCity, Maven Build not found child module

I've Maven project with one subproject, when I run my install task on parent project from IDEA (IntelliJ IDEA) all works fine and maven resolve child module.
My projects are versioned on subversion, and this is the filesystem structure:
project
|--pom.xml
|--subproject
|
|-- branches
|-- tags
|-- trunk (here there is my subproject source, also pom.xml file)
I've create project with its subproject, from svn URL, on teamcity server.
When I run Build on parent project it fail and return me the following error:
[Step 1/1] Error reading Maven project: Some problems were encountered while processing the POMs:
[ERROR] Child module /opt/buildAgent/work/ee114e0c77ee2c44/subproject of /opt/buildAgent/work/ee114e0c77ee2c44/pom.xml does not exist #
How can I say to parent-project-build where it find the child module?
Is there something else wrong?
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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>it.company.project</groupId>
<artifactId>MyProject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>MyProject</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<modules>
<module>Foo</module>
</modules>
</project>
Child POM:
<?xml version="1.0"?>
<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>
<parent>
<groupId>it.company.project</groupId>
<artifactId>MyProject</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>it.company.subproject</groupId>
<artifactId>subproject</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>subproject</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</resource>
</resources>
</build>
</project>
EDIT:
I added new parameter (pathSubproject) to my parent pom.xml, so when I run the parent build it skipped the previous error, but now it crash when trying to resolve parent dependency on the subproject. So I added a new parameter also at subproject (parentPath) and I passed it to relativePath inside parent tag.
Non-resolvable parent POM: Could not find artifact it.company.project:MyProject:pom:1.0-SNAPSHOT and 'parent.relativePath'
I think that my subproject POM not resolve the properties that I put inside <relativePath tag.
Is possible pass a properties to relativePath tag?
Thanks
In the <modules/> section of your parent project's pom, each module listed is a relative path to the directory containing the module.
So if you don't want to change the directory structure, you should be able to refer to the trunk of your subproject using <module>subproject/trunk</module>.
This does seem a bit clumsy though. If you are using the aggregator / modules pattern, I would recommend that project and subproject are both in the same SVN respository. If that isn't appropriate, then your subproject might not really be a module, and should be a dependency or have project as its parent artifact.
I solve my problem by creating 2 profile in my parent pom, the first one builds the parent application with all submodules, while the latter build only the the parent application.
In TeamCiTY build configuration settings I specified (inside Additional Maven command line parameters) the profile that build only parent module, and after I built the parent Application.
After that I built the parent application I built all submodules, and then I was able to build parent application with all modules.
I'm not sure that this is the right way, but in my case it worked well.

Set filename of package generated by maven

I've got a pom.xml file which builds an Java Spring artifact to a war-file.
The war-file-name for the example below is always artifact 1.0.war
I want it to be just artifact.war because I need to deploy it to a Tomcat server where all url-configurations are overwritten.
How can I remove the version from the package file-name?
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.company</groupId>
<artifactId>artifact</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>MyArtifact</name>
...
</project>
You can give in the build section:
<build>
..
<finalName>${artifactId}-${version}</finalName>
..
</build>
Or just change the context path in the web.xml (or may be in tomcat).

Resources