How to set permissions for directories on maven output?

I am using maven-assembly-plugin to package my assembly.

I can do some copying of sets of files and change the file permissions, but I can’t change the directory permissions. From the documentation I am trying to use in directories that excite me. However, no matter what permissions I specify, directories are ALWAYS created based on the current umask (0022). Does anyone know of a clean way to change directory permissions this way during Maven builds. The only thing that works is umask 0 , but I would prefer not to force it, since everyone who works on this project would have to have this set.

Example maven assembly.xml:

 <?xml version="1.0"?> <assembly> <id>zip-with-dependencies</id> <formats> <format>dir</format> <format>tar.gz</format> </formats> <includeBaseDirectory>true</includeBaseDirectory> <dependencySets> <dependencySet> <includes> <include>foo:bar</include> </includes> <outputDirectory>/resources/blah</outputDirectory> <useProjectArtifact>true</useProjectArtifact> <unpack>true</unpack> <scope>runtime</scope> </dependencySet> </dependencySets> <fileSets> <fileSet> <directory>${basedir}/src/main/web</directory> <includes> <include>some_dir</include> </includes> <outputDirectory>web</outputDirectory> <fileMode>0777</fileMode> <directoryMode>0777</directoryMode> </fileSet> </fileSets> </assembly> 
+1
source share
3 answers

I had the same problem. I tested all of the above solutions, and none of them worked for me. The best solution I had in mind, and it worked for me, was to pre-create these parent folders as empty folders before writing them.

So, to relate to the original problem, you should use:

 <fileSet> <directory>./</directory> <outputDirectory>/resources</outputDirectory> <excludes> <exclude>*/**</exclude> </excludes> <directoryMode>0700</directoryMode> </fileSet> 

This should be placed before in the actual copy in the resource subfolder in your example.

./- this is just an existing folder. It can be any other folder if it exists. Please note that we exclude any file from the file. Thus, the result will be an empty folder with the appropriate set of permissions.

On the side of the note, whoever uses tar to package files, without this set, the tar file will not have the permissions set for this parent folder. Thus, the extraction will lead to the creation of a new folder, but with the permissions of the extracting user + his umask.

0700 was used, of course, just for example.

+2
source

I found a JIRA problem describing this behavior. The workaround should be

 <configuration> <archiverConfig> <fileMode>420</fileMode> <!-- 420(dec) = 644(oct) --> <directoryMode>493</directoryMode> <!-- 493(dec) = 755(oct) --> <defaultDirectoryMode>493</defaultDirectoryMode> </archiverConfig> </configuration> 
+1
source

I solved this problem with a combination of settings in pom.xml and an assembly descriptor.

In pom, specify default values ​​for the entire zip file.

  <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>2.2.2</version> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> <configuration> <descriptors> <descriptor>src/main/assembly/descriptor.xml</descriptor> </descriptors> <archiverConfig> <directoryMode>0755</directoryMode> <defaultDirectoryMode>0755</defaultDirectoryMode> <fileMode>0644</fileMode> </archiverConfig> </configuration> </plugin> 

Then, in the assembly descriptor, I provide overrides for individual folders that should not have default permissions.

 <fileSets> <fileSet> <directory>src/conf</directory> <outputDirectory>conf</outputDirectory> <fileMode>0600</fileMode> <directoryMode>0700</directoryMode> </fileSet> <fileSet> <directory>src/db</directory> <outputDirectory>db</outputDirectory> </fileSet> <fileSet> <directory>src/bin</directory> <outputDirectory>bin</outputDirectory> <fileMode>0755</fileMode> </fileSet> 

Here, the files in the bin will receive executable state for all users. The conf directory and files in it are accessible only to the owner, and the db directory inherits permissions from the settings in pom.

Assembly file settings are described in http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html

I could not find any official documentation in the configuration section other than the JIRA problem identified by amra.

+1
source

Source: https://habr.com/ru/post/957949/


All Articles