Maven Assembly : How to generate a zip file for each environment ? - maven-3

I have a static project with html, js, css and conf files like this :
project
- static
- conf
conf-int.json
conf-rec.json
conf-prd.json
-js
-html
-images
- pom.xml
- assemblyDescriptor.xml
Here is my assembly descriptor :
<id>zip</id>
<baseDirectory>/</baseDirectory>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>static/conf/</directory>
</fileSet>
</fileSets>
</assembly>
Here is my build conf in pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>zip.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>trigger-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I want to generate my zip with either conf-int.json or conf-rec.json or conf-prd.json corresponding to differents environments i have. If it were a java project i would use profil maven with profil and/or classifier. But i don't know how to generate a zip file for each environment with maven-assembly. Could you give me some advice please ?

You can have multiple execution defined in your assembly plugin (each with distinct execution id and different assembly descriptor file). In the respective descriptor you define which file to include.

Related

Access additional test files for Appium tests on AWS device farm

I am running Appium tests with JUnit on AWS device farm. Is there a way to upload additional test files and access them from within my code? So basically, can I access the file system of the container that runs the Appium tests?
I have the necessary files within my JAR file (which is inside a zip as per AWS requirements) but I'm not sure if and where AWS extracts the files from this JAR during the test run (probably not).
There is an option called Add extra data which can be used to upload files but I'm not sure how to access them from within my code. The documentation states:
For iOS, the extra data is actually inside the app installation
directory [...] On Android, we unarchive it in a root directory of the
sdcard.
Does this mean I would need to pull the files from the phone (Appium could do that) and put them in some temp folder? I could also try to pull the files from a git repo or a web share but I was hoping there would be a simpler way to access the file system. Another concern is whether there is some restriction which wouldn't allow me to write to the file system at all.
Does anyone have any experience with this?
There are two way that I know of to access additional files on the device host.
Include it in the jar(as you're already doing) and then access the files using the current thread. SO Post where I did this
InputStream input = null;
//load in the properties file from src/test/resources
try {
input = Thread.currentThread().getContextClassLoader().getResourceAsStream("myproperties.properties");
// load a properties file
prop.load(input);
// get the property value and print it out
System.out.println(prop.getProperty("devicefarm"));
} catch (IOException ex) {
ex.printStackTrace();
}
Include it in the zip uploaded to Device Farm using the copy resources plugin.
POM:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/dependency-jars/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/dependency-resources</outputDirectory>
<resources>
<resource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>zip-with-dependencies</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/zip.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
ZIP.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>zip</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>./</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>./</outputDirectory>
<includes>
<include>/dependency-jars/</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>./</outputDirectory>
<includes>
<include>/dependency-resources/</include>
</includes>
</fileSet>
</fileSets>
</assembly>
We can then access the additional files that are packaged in the zip uploaded to Device Farm using the path ./dependency-resources/somefilename
Device Farm's SDK will unzip the test package to the Device host machine to the /tmp directory. If you export the /tmp directory on the specify device state page you can export the same test package you uploaded using custom artifacts.
The extra data feature you mentioned will only put additional files in the device and not the device host running the tests. Also using appium to pull and push files I believe only works on simulators and not real device currently.
https://discuss.appium.io/t/pull-file-from-ios-device/1541/3
-James

Rinsim, compile executable file failed, with maven dependency

I try to get a executable file for my code using this maven plug from How can I create an executable JAR with dependencies using Maven?. However it ends up with the error Failed to execute goal com.mycila:license-maven-plugin:3.0:check (check-license) on project rinsim-example: Execution check-license of goal com.mycila:license-maven-plugin:3.0:check failed: Cannot read header document LICENSE_HEADER. Cause: Resource LICENSE_HEADER not found in file system, classpath or URL: no protocol: LICENSE_HEADER -> [Help 1]>
this is the part of my maven file:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.github.rinde.rinsim.examples.project.DDRP</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-my-jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
Thank you.
It seems like you've copied part of the RinSim pom.xml, including the license-maven-plugin? You should probably remove the license-maven-plugin plugin execution, as that is the source of this error message. This is the definition of the license-maven-plugin in RinSim:
<pluginExecution>
<pluginExecutionFilter>
<groupId>com.mycila</groupId>
<artifactId>
license-maven-plugin
</artifactId>
<versionRange>
[2.11,)
</versionRange>
<goals>
<goal>check</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
Alternatively, you can choose to use the license-maven-plugin. This plugin allows you to set a license header on every source file.

maven-dependency-plugin:unpack Error

I'm trying to extract some .exe files from a dependency jar file and put them under ${project.build.directory}/classes/.
But when I execute:
mvn clean compile dependency:unpack
I get:
Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.10:unpack (default-cli) on project simple: Either artifact or artifactItems is required -> [Help 1
I have verified that the dependencies are available in my local repository.
In my example pom below I've used junit as an example, but no matter which dependency I list, I get the same error.
pom.xml:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>unpack</id>
<phase>package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/classes/externaltools</outputDirectory>
<includes>**/*.txt</includes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
The issue is due to you cannot use mvn clean compile dependency:unpack and <executions> tags together.
In documentation Maven Depdendency Plugin at the bottom part of the page you can read:
If you intend to configure this mojo for execution on the command line using: mvn dependency:unpack you must not put the configuration inside the executions tag. Your configuration should look like this:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<configuration>
<artifactItems>
<artifactItem>
<groupId>[ groupId ]</groupId>
<artifactId>[ artifactId ]</artifactId>
<version>[ version ]</version>
<type>[ packaging ]</type>
<classifier> [classifier - optional] </classifier>
<overWrite>[ true or false ]</overWrite>
<outputDirectory>[ output directory ]</outputDirectory>
<destFileName>[ filename ]</destFileName>
<includes>[ comma separated list of file filters ]</includes>
<excludes>[ comma separated list of file filters ]</excludes>
</artifactItem>
</artifactItems>
<!-- other configurations here -->
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
I have tried removing the <execution> tags and works perfectly!

move the maven-onejar generated jar to a custom location

I am using the onejar-maven-plugin to generate the jar for my project and it all goes well. But, when I try to change it to a sub-folder, for eg. dist, the jar from maven-jar-plugin gets generated, not the jar from onejar.
The onejar plugin does not have an output directory option.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<outputDirectory>${project.build.directory}/dist</outputDirectory>
<archive>
<manifest>
<mainClass>com.ss.itempriceclient.ItemPriceUploader</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.dstovall</groupId>
<artifactId>onejar-maven-plugin</artifactId>
<version>1.4.4</version>
<executions>
<execution>
<configuration>
<classifier>onejar</classifier>
</configuration>
<goals>
<goal>one-jar</goal>
</goals>
</execution>
</executions>
</plugin>
How do I change the output directory of the onejar generated file to a subfolder, eg. dist?
I finally went with maven-assembly-plugin. Has lots of configuration options.

m2 release plugin couldn't recognize assembly file with parameterized name

In my POM.xml file, I am using assembly plug in. I want the build to assemble things based on the assembly file, whose name is parametrized. The build works fine. However, if I use m2 release plug in using perform release action in jenkins, the release plugin could not substitute the value for $env and pick up the assembly.xml file. I get the following exception.
Caused by: org.apache.maven.plugin.assembly.io.AssemblyReadException: Error locating assembly descriptor: src/main/assembly/${env}.xml
I have attached the log and POM file.
POM file build portion:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution>
<execution>
<id>dist</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuraenter code heretion>
<descriptors>
<descriptor>src/main/assembly/${env}.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
<plugin>

Resources