See my answer on StackOverflow. I hope it helps.
https://stackoverflow.com/a/67158497/1082681

-- 
Alexander Kriegisch
https://scrum-master.de


Amedee Van Gasse schrieb am 19.04.2021 14:42 (GMT +07:00):

> I do not ever want maven-dependency-plugin:3.1.2:unpack to overwrite existing
> files in any circumstances. This is my current pom.xml configuration:
> 
>   <plugin>
>     <artifactId>maven-dependency-plugin</artifactId>
>     <version>3.1.2</version>
>     <executions>
>       <execution>
>         <id>unpack-zip-files</id>
>         <phase>generate-test-resources</phase>
>         <goals>
>           <goal>unpack</goal>
>         </goals>
>         <configuration>
>           <artifactItems>
>             <artifactItem>
>               <groupId>com.foo</groupId>
>               <artifactId>bar</artifactId>
>               <version>${foobar.version}</version>
>               <type>zip</type>
>               <classifier>exe-archive</classifier>
>               <overWrite>false</overWrite>
>               
> <outputDirectory>${project.build.directory}/lib</outputDirectory>
>               <includes>**/*.exe</includes>
>             </artifactItem>
>           </artifactItems>
>           <overWriteIfNewer>false</overWriteIfNewer>
>           <overWriteReleases>false</overWriteReleases>
>           <overWriteSnapshots>false</overWriteSnapshots>
>         </configuration>
>       </execution>
>     </executions>
>   </plugin>
> 
> ***Scenario***
> 
> * Projects foo and bar
> * foo has a .exe file as build artifact, inside a ZIP file
> * bar runs the .exe file during tests
> * In situation X, bar must use the snapshot version of the mainline 
> development
> branch of foo. In that case, the directory target/lib shall be empty before 
> mvn
> install. This is guaranteed by starting from an empty workspace and running 
> mvn
> clean as a separate build step. This question is not about situation X.
> * In situation Y, bar must use a custom build of a feature branch of foo. This
> is done by unpacking the ZIP file with the .exe to the directory target/lib in
> a separate build step between mvn clean and mvn install.
> * We are working in situation Y, where the target/lib directory is already
> pre-filled with the .exe from the correct feature branch.
> 
> This is the target/lib directory before mvn is run:
> 
> + ls -al fooBar.exe
> -rw-rw-r-- 1 ubuntu ubuntu 18368427 Apr 12 21:27 fooBar.exe
> + md5sum fooBar.exe
> 03acc8b5c3da700c31efcd6635feb56a  fooBar.exe
> 
> This is the target/lib directory after mvn is run:
> 
> + ls -al fooBar.exe
> -rwxrwxr-x 1 ubuntu ubuntu 18368393 Apr 11 23:10 fooBar.exe
> + md5sum fooBar.exe
> ab6dd45c5cc4e41534ad2363c5767601  fooBar.exe
> The change in md5sum is hard evidence that the existing fooBar.exe was
> overwritten by Maven.
> 
> ***Maven command used***
> 
> mvn --global-settings
> /home/jenkins/workspace/bar@tmp/config15592668079584895681tmp \
>     -Dmaven.repo.local=/home/jenkins/workspace/bar/.repository \
>     install \
>     -DgsExec=/usr/bin/gs -DcompareExec=/usr/local/bin/compare \
>     -Dtest=RunCucumberTest -Dcucumber.options=--plugin
>     json:target/cucumber.json
> 
> ***Expected results***
> 
> * The mvn install command shall not overwrite existing files when overWrite,
> overWriteIfNewer, overWriteReleases, overWriteSnapshots are all set to false.
> * The md5sum of fooBar.exe shall be the same before and after running mvn
> install.
> 
> ***Question***
> 
> Which magical incantations do I need to add to pom.xml so that existing files
> are never overwritten in any circumstances?
> 
> ***Documentation referenced***
> 
> https://maven.apache.org/plugins/maven-dependency-plugin/usage.html#Overwrite_Rules
> https://maven.apache.org/plugins/maven-dependency-plugin/unpack-mojo.html
> 
> Also asked on Stack Overflow, but I didn't get an answer there:
> https://stackoverflow.com/questions/67066164/maven-dependency-plugin-unpack-goal-do-not-overwrite-existing-files
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to