Installing MAVEN build dependencies [OSGi bundles] with Maven in to Adobe CQ - maven

We have an CQ REST API project to share content with our consumers. The bundle is created with osgi jax-rs connector. We are still in incubation state, but it seems the integration is working fine.
The issue we are facing is the "osgi jax-rs connector" project requires some bundles (osgified ones, provided by the project) to be installed in CQ. Currently we are doing this manually, using the felix console.
Can we automate the process using MAVEN (we can install the bundle which we created using MAVEN).
Any pointers to this would be helpful.
San

If you also have a UI package, e.g. a ZIP that gets installed with the maven-vault-plugin you can place JAR files in any folder. I usually call it install:
/apps/myproject/install
There is a handler in CQ that recognizes JAR files in a content package and installs them to OSGi.

If you are building a zip package to install you can have the bundles installed with maven and not include the dependencies in your project adding additional space to your SCM.
To do this you can use the maven-assembly-plugin plugin.
For example include this in your pom.xml:
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/zip.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
And then in you zip.xml you would create an assembly file like this:
<?xml version='1.0' encoding='UTF-8'?>
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>zip</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${basedir}/src/main/content/jcr_root</directory>
<outputDirectory>jcr_root</outputDirectory>
<excludes>
<exclude>**/.DS_Store</exclude>
</excludes>
<filtered>false</filtered>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputDirectory>jcr_root/apps/myapp/install</outputDirectory>
<useProjectArtifact>false</useProjectArtifact>
<scope>compile</scope>
<includes>
<include>com.my.groupid:my-maven-artifact-id</include>
</includes>
<useStrictFiltering>true</useStrictFiltering>
</dependencySet>
</dependencySets>
</assembly>
You can adjust the dependency set and file set settings as needed. Obviously I made up an AEM app name and maven artifact.

Related

In Maven, can I pack JEE project in Zip archive together SQL scripts?

Hello everyone first of all,
Suppose I have a JEE project contents some modules and a 'sql' folder inside:
I build all modules to a 'integration-version.ear' archive file.
There is the content of my target:
Using Maven, can I build something like this:
There is the ‘3.15’ folder includes some SQL files from the same folder of my project.
Is it possible? What is configuration of Maven needed?
Note:
The original question was like: "In Maven, can I pack JEE project in RAR archive together SQL scripts?" but now the question is changed because RAR is a proprietary format and each tools that create RAR files must be commercially licensed.
Solution:
Using build-helper-maven-plugin
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>parse-version</goal>
</goals>
<configuration>
<propertyPrefix>parsedVersion</propertyPrefix>
</configuration>
</execution>
...
Using maven-assembly-plugin
pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<inherited>false</inherited>
<configuration>
<descriptors>
<descriptor>${project.basedir}/../assembly.xml</descriptor>
</descriptors>
</configuration>
...
assembly.xml
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>release</id>
<baseDirectory>${file.separator}</baseDirectory>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.basedir}/../sql/migrates/${parsedVersion.majorVersion}.${parsedVersion.minorVersion}</directory>
<outputDirectory>/scripts-${parsedVersion.majorVersion}.${parsedVersion.minorVersion}</outputDirectory>
<includes>
<include>**/*.sql</include>
</includes>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputFileNameMapping>${build.finalName}.${packaging}</outputFileNameMappin>
<includes>
<include>*:ear</include>
</includes>
</dependencySet>
</dependencySets>
</assembly>
There are 2 Maven plugins which can do that: maven-assembly-plugin and maven-rar-plugin
If you want to use maven-rar-plugin, i would create a new module with packaging rar and configure the plugin.
I personally think maven-assembly-plugin is easier to use.

How deploy a zip file whith Maven assembly plugin in the artifactory referentiel

I develop a web application that has two layers: a frontend layer and a backend. I deployed the backend war in artifactory using distributionManagement. Now I want to deploy the frontend. I use maven assembly plugin. I made a zip. I would like to know how to deploy the frontend zip in artifactory? Thank you for your help.
<!-- Maven assembly plugin -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>myArchive</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/assembly/zip.xml</descriptor>
</descriptors>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution>
</executions>
</plugin>
<!--My zip.xml-->
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>WebContent</id>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>WebContent</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>**/*.*</include>
</includes>
</fileSet>
</fileSets>
</assembly>
You can use maven command to deploy separate files:
mvn -X clean package deploy:deploy-file -Dfile=/frontend-1.0.zip

Mule: building embedded application with Maven

Is there a way to build a Mule application as an embedded stand-alone jar using Maven (possibly with a help of Mule maven plugin)?
How the pom should be configured if so?
The MuleSoft documentation says that you can create an embedded app by adding all the dependencies manually. But I hope there is a way to automate this task.
Thank you,
You can create a Maven application and depend only on org.mule.distributions:mule:jar:embedded:3.7.0 but this won't create an app with all Mule classes inside of it, which I think is a useful approach (though I don't understand your scenario).
If you need all dependencies to be packaged in your application bundle you can use Maven Assembly Plugin to include all dependencies in a zip file. First add the plugin configuration to your pom like this:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
And add an assembly.xml file in your project root directory containing this:
<assembly>
<id>application-name</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<scope>runtime</scope>
<fileMode>0644</fileMode>
</dependencySet>
</dependencySets>
</assembly>

maven copy-dependencies includeGroupIds and all transitive elements to those

I try to figure out how to copy all dependencies to an explicit version and all the required dependencies.
For Example: My project requires version 3 of a third party lib, called foobar.
I want to copy the version 3 libraries to a folder named lib-foobar-${foobar.version}.
In this folder are those jars which are required to use foobar in version 3. That means the jar itself and all dependent jars which are declared in the foobar pom.
I currently use the org.codehaus.mojo:maven-dependency-plugin:2.1 with goal copy-dependencies in phase package.
My configuration is:
<configuration>
<outputDirectory>${project.build.directory}/lib-foobar-${foobar.version}</outputDirectory>
<includeGroupIds>com.foobar</includeGroupIds>
<excludeTransitive>false</excludeTransitive>
<excludeScope>test</excludeScope>
<includeScope>compile</includeScope>
</configuration>
I don't want to list all allowed and not allowed lib's because a step to a newer version takes place every month.
Are there any other tools which can do that or is there any dodge for that?
Big thanks to user944849.
It was very helpful to me for finding out the best solution in that case.
For everyone who is interested in my solution, here it comes:
At first I changed the plugin to maven-assemby-plugin and added a new assembly file
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<dependencies>
<dependency>
<groupId>com.foobar</groupId>
<artifactId>foobar-parent</artifactId>
<version>${foobar.version}</version>
<type>pom</type>
</dependency>
</dependencies>
<executions>
<execution>
<id>copy-foobar</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/assemble/foobar-libs.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
And the assembly file looks like:
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>standalone</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<includes>
<include>org.foobar</include>
</includes>
<outputDirectory>/lib-foobar-${foobar.version}</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<useTransitiveFiltering>true</useTransitiveFiltering>
<unpack>false</unpack>
</dependencySet>
</dependencySets>
</assembly>
The key was the <useTransitiveFiltering> element, which resolves all transitive libs based on the included libs.

Maven: creating an archive (zip or jar) file containing files outside the project?

I'm currently working on a Maven based project in which I have unit tests that generate PDF files in, let's say "C:/result" directory (I definitely don't want these files to be created within any directory from my project).
Using the maven-assembly plugin, would it be possible to create an archive file (preferably zip or jar) that gathers the files that are thus generated in "C:/result"?
Basically, my goal would be to upload this archive as a regular artefact onto a Nexus server, every time I deploy a new version of my project.
Thx in advance.
You'd need to define an assembly descriptor similar to:
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>bin</id>
<formats>
<format>zip</format>
</formats>
<baseDirectory>C:/</baseDirectory>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>results</directory>
<outputDirectory>./doc</outputDirectory>
</fileSet>
</fileSets>
</assembly>
Save e.g. as src/assembly/bin.xml, it will be referred from the pom.
The pom would contain in the build section:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>out</id>
<configuration>
<descriptors>
<descriptor>src/assembly/bin.xml</descriptor>
</descriptors>
</configuration>
<phase>verify</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
see for more information maven assembly documentation.

Resources