質問

How do I preserve the time-stamp of jars that have not changed inside my lib folder?

I am using Robocopy to mirror sync my server lib folder with my local machine. I copy all my jars to the lib folder on the server over a somewhat slow vpn connection and want to copy only the ones that changed and delete any no longer needed ones.\

What I need is a way to ensure that in my Maven build, that the jars I don't need in the lib folder are removed and the jars copied into the lib folder are only the newer ones that were not there before.

I do not want the folder completely rebuilt because that will modify the time-stamp on the jars and then ... I will have to copy them all to the server!!

This would be fine if the jars had their original time-stamp preserved by maven so that the time-stamp stayed the same as found in my maven repository. Unfortunately, Maven gives them all a fresh time-stamp.

I am using a standard maven setup pom to create a lib folder with all dependencies:

<plugin>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>install</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                            <mainClass>${mainClass}</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

Notes:

Most of my depends jars are stable release jars and most of my project depends are snapshot jars. Regardless, the timestamp of the original library jar needs to be the timestamp of the copy placed in lib.

Given that the jars in lib are copies or jars in the local mvn repository, a mvn clean install should also preserve file lastmod times of the copies it places in lib. At least, that should be the default behavior since the lib contains bonafide copies of the original mvn fetched jar files.

Also interesting, mvn preserves file times from fetched jars when it puts them into local repositories. The plugin is the culprit, since it is responsible for copying jars into lib and it assigns new time stamps to them (argg)!

役に立ちましたか?

解決

If you don't mind NOT using maven-dependency-plugin, you can try to use these configuration inside your pom.xml:

<build>
    <plugins>
        <plugin>
            <groupId>com.github.goldin</groupId>
            <artifactId>copy-maven-plugin</artifactId>
            <version>0.2.5</version>
            <executions>
                <execution>
                    <id>copy-deps</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <resources>
                            <resource>
                                <targetPath>${project.build.directory}/lib</targetPath>
                                <dependency>
                                    <includeScope>compile</includeScope>
                                </dependency>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

I've tried this in my local machine and it seems to produce the same timestamp as the JARs in my local M2 repository.

More info on the plugin here:
http://evgeny-goldin.com/wiki/Copy-maven-plugin

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top