Creating Symlink for dependencies in a Maven assembly

I have a Maven assembly that, after unpacking tar, creates three directories, each of which contains the / lib directory. For example,

folder1/lib
folder2/lib
folder3/lib

I am currently compiling the same .jar in each of these / lib directories. Since this is a waste of space, I was wondering if I can only have one copy of this .jar and create something like a symbolic link for the other two locations that could reference this .jar?

Thank!

+4
source share
3 answers

maven-antrun-plugin . Zookeeper ${basedir}/target/package/lib maven-dependency-plugin. ${basedir}/target/package/lib/zookeeper/lib, 2 dirs upper.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
        <execution>
            <id>prepare-delivery</id>
            <phase>package</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <target>
                    <!-- Prepare zookeeper layout. -->
                    <mkdir dir="${basedir}/target/package/lib/zookeeper/lib"/>
                    <apply executable="ln" dir="${basedir}/target/package/lib/zookeeper/lib" relative="true">
                        <arg value="-s"/>
                        <srcfile prefix="../../"/>
                        <targetfile/>
                        <fileset dir="${basedir}/target/package/lib" includes="**"/>
                        <mapper type="identity"/>
                    </apply>
                </target>
            </configuration>
        </execution>
    </executions>
</plugin>

antrun :

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
</plugin>
+4

, Maven. "" . JIRA ( ), : Plexus. , , - , .

FYI, " ", , tar. " ", , tar. , Maven - , , tar-in untar-ing .

, tar Maven, . , , , , exec-maven-plugin, maven-antrun-plugin.

, Windows. , , , tar, , , . , .

exec , , . , , , tar. , .

, , antrun Ant symlink - Ant , Maven. . , tar, . OS X Linux, - , .

, , , , , , .

+2

/ ant -run plugin

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <phase>package</phase>
            <configuration>
                <target>
                    <symlink link="folder2/lib/${project.artifactId}-${project.version}.jar"
                             resource="folder1/lib/${project.artifactId}-${project.version}.jar"/>
                    <symlink link="folder3/lib/${project.artifactId}-${project.version}.jar"
                             resource="folder1/lib/${project.artifactId}-${project.version}.jar"/>
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>

If you want symbolic links to have a relative path, you can specify a relative path in the resource, as shown below

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <phase>package</phase>
            <configuration>
                <target>
                    <symlink link="folder2/lib/${project.artifactId}-${project.version}.jar"
                             resource="../../folder1/lib/${project.artifactId}-${project.version}.jar"/>
                    <symlink link="folder3/lib/${project.artifactId}-${project.version}.jar"
                             resource="../../folder1/lib/${project.artifactId}-${project.version}.jar"/>
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>
0
source

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


All Articles