How to create a zip archive with some readonly files with maven-assembly-plugin - maven

I have a project with 2 files (src/foo/a.txt and src/foo/b.txt) and I want to create a zip archive where b.txt is in readonly.
Here's my environment:
Windows 7
JRE 1.8.0_112
Maven 3.3.3
maven-assembly-plugin 3.0.0
7-Zip 9.20
Here's my pom.xml:
<?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>
<groupId>org.foo</groupId>
<artifactId>foo-zip</artifactId>
<version>0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>package</phase>
<goals><goal>single</goal></goals>
</execution>
</executions>
<configuration>
<encoding>UTF-8</encoding>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/foo-assembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
</build>
</project>
and here's my assembly descriptor:
<?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>foo-zip</id>
<includeBaseDirectory>false</includeBaseDirectory>
<formats><format>zip</format></formats>
<fileSets>
<fileSet>
<directory>src/foo</directory>
<excludes><exclude>b.txt</exclude></excludes>
<outputDirectory />
</fileSet>
<fileSet>
<directory>src/foo</directory>
<includes><include>b.txt</include></includes>
<fileMode>0444</fileMode>
<outputDirectory />
</fileSet>
</fileSets>
</assembly>
When I unzip the generated archive, and open the properties of b.txt, the "readonly" checkbox is not checked.
I'm aware of:
Maven assembly plugin not applying fileMode on unpacked dependencySet and maven assembly plugin do not set file attributes but they haven't helped me much.
I tried various fileMode values (0444 or 0544) but I just can't get my file to be uncompressed in readonly mode.
Any ideas?

Related

How to get the final result of a multi module project in the root project directory folder?

I have a a multi modules project such as:
project:
- module1
- module2
- packaging
The module 1 and 2 respectively generate a jar and the packaging use the maven assembly to put everything into a zip file.
The result looks like:
final-archive.zip:
- module1.jar
- module2.jar
The issue I'm facing is that the resulting zip is in the packaging folder of my project and not in the root folder of the project directory.
How can I have the final result of my build at the place I wish to ?
The main pom.xml
<?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>
<packaging>pom</packaging>
<name>groupId :: Name :: Project</name>
<groupId>groupId</groupId>
<artifactId>project</artifactId>
<version>1.0.0</version>
<modules>
<module>module1</module>
<module>module2</module>
<module>packaging</module>
</modules>
</project>
The packaging pom.xml
<?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>
<packaging>pom</packaging>
<name>groupId :: Project :: Packaging</name>
<artifactId>packaging</artifactId>
<properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>${maven-assembly-plugin.version}</version>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>install</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
The assembly
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>packaging-assembly</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<files>
<file>
<source>../module1/target/jar-module1-${version}.jar</source>
</file>
<file>
<source>../module2/target/jar-module2-${version}.jar</source>
</file>
</files>
</assembly>

IntelliJ says: <encoding> not allowed in maven-jaxws-tools-plugin

In my 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/maven-v4_0_0.xsd">
<build>
<plugins>
<plugin>
<groupId>org.jboss.ws.plugins</groupId>
<artifactId>maven-jaxws-tools-plugin</artifactId>
<executions>
<execution>
<id>wsconsume</id>
<goals>
<goal>wsconsume</goal>
</goals>
<configuration>
<wsdls>
<wsdl>${project.build.directory}/dependency-schemas/wsdl/myWsdl.wsdl</wsdl>
</wsdls>
<extension>true</extension>
<verbose>false</verbose>
<encoding>UTF-8</encoding>
<bindingFiles>
<bindingFile>${project.build.directory}/dependency-schemas/wsdl/jaxb_bindings.xml</bindingFile>
</bindingFiles>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<!-- more stuff -->
</project>
IntelliJ marks UTF-8 as red. Furthermore it says: "Element encoding is not allowed here".
Can I just remove it?
The default value for the encoding for maven-jaxws-tools-plugin is the value of ${project.build.sourceEncoding}. You can also set that in the properties like this:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
As far as i know the default encoding on windows is for example cp1252, maybe thats why your intellij is complaining?

How to prevent 'Error creating assembly archive distribution: A zip file cannot include itself'

I have a multi module project and I want to make a zip with all sources (and other files). I use maven-assemble-plugin.
I found a way with dependencySet, but I do not want add all my module sources (and later javadoc, too) as dependencies. I tried to use moduleSet, but I get an error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.6:single (make-zip) on project test-distribution: Failed to create assembly: Error creating assembly archive distribution: A zip file cannot include itself -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.6:single (make-zip) on project test-distribution: Failed to create assembly: Error creating assembly archive distribution: A zip file cannot include itself
My pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>make-zip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/assemble/distribution.xml</descriptor>
</descriptors>
<appendAssemblyId>false</appendAssemblyId>
<finalName>test</finalName>
</configuration>
</execution>
</executions>
</plugin>
My assembly descriptor:
<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>distribution</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<moduleSets>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<sources>
<outputDirectory>/Sources</outputDirectory>
</sources>
</moduleSet>
</moduleSets>
</assembly>
With dependencySet I could fix that problem with option useProjectArtifact, but I found no option for moduleSet. Is there any way to exclude the current project's build?
I find a way to exclude current project's build:
<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>distribution</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<moduleSets>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<excludes>
<exclude>*:test-distribution</exclude>
</excludes>
<sources>
<outputDirectory>/Sources</outputDirectory>
</sources>
</moduleSet>
</moduleSets>
</assembly>

use maven-assembly-plugin , but jar only contain dependency project's classes, no app project classes

I have a library project which I declared as a <dependency> of my App project.
The library project's pom.xml:
<?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>
<groupId>com.my.library</groupId>
<artifactId>MyLib</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>MyLib</name>
...
My App project's pom.xml:
<?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>
<groupId>com.my.app</groupId>
<artifactId>MyApp</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>MyApp</name>
<dependencies>
<!--include library project as a dependency-->
<dependency>
<groupId>com.my.library</groupId>
<artifactId>MyLib</artifactId>
<version>1.0</version>
</dependency>
...
</dependencies>
Since I need an jar which includes classes of my library project, so I declared also maven-assembly-plugin in my App project's pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptor>assembly.xml</descriptor>
</configuration>
<executions>
<execution>
<id>make-jar</id>
<phase>package</phase>
<goals>
<goal>assembly</goal>
</goals>
</execution>
</executions>
</plugin>
The assembly.xml looks like this:
<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>jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>runtime</scope>
<includes>
<!--inclucde classes from my library project-->
<include>com.my.library:MyLib</include>
</includes>
</dependencySet>
</dependencySets>
</assembly>
Ok, at this point, I run mvn clean install under my App project, under target/ directory, I got MyApp-jar-with-dependencies.jar.
But when I check the content of above jar, it only contains classes of my library project but doesn't contain my App project's classes? WHY?

when installing artifact *zip file doesn't appear in local repo

I have project with some configuration files and after run maven install I got *.zip archive in target directory. However in my local repo I have only pom file. I auusme it's because of <packaging>pom</packaging> drfined in pom.xml. How can I get *.zip file in local repo anyway?
Here is the pom
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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>com.mycomp.name</groupId>
<artifactId>saas-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../saas-parent/pom.xml</relativePath>
</parent>
<!-- TEST -->
<artifactId>htdocs</artifactId>
<name>htdocs</name>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>assembly</id>
<goals><goal>single</goal></goals>
<phase>package</phase>
</execution>
</executions>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>${project.basedir}/src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
</build>
</project>

Resources