70756

Maven doesn't copy untracked resources while releasing

My problem is about resources to be included in the jar file when doing release with maven.

I am using maven to build my project and when I run

$ mvn package

resources are included in the output jar. But when I run

$ mvn release:prepare $ mvn release:perform

these resources are not included in the release jar.

Resources are located in maven default directory, src/main/resources, but they are outside of source control (ignored via .gitignore). From the output made by maven I realize that maven does git checkout to different folder and resources are not copied to that folder. This is why maven release plugin doesn't package it to release jar.

My question is what is the best way to deal with such a case?

<ol> <li>

Make a symlink for resources folder during release process? how?

</li> <li>

Copy resources? how?

</li> <li>

Or putting resources into SCM is the only way to make them available in released package?

</li> </ol>

I prepared small testcase for this:

#!/bin/sh # here is pom.xml cat >pom.xml <<EOF <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> <groupId>com.domain</groupId> <artifactId>artifact</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>artifact</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <scm> <developerConnection>scm:git:file://$(pwd)</developerConnection> </scm> <distributionManagement> <repository> <id>internal.repo</id> <name>Example Internal Repository</name> <url>file://$(pwd)/deploy</url> </repository> </distributionManagement> </project> EOF #here is src/main/java/Main.java mkdir src mkdir src/main mkdir src/main/java mkdir src/main/resources cat >src/main/java/Main.java <<EOF import java.io.InputStream; public class Main { public static void main(String args[]) { boolean ok = false; InputStream is = new Main().getClass().getResourceAsStream("/some_file_outside_scm"); ok = is != null; System.out.println("ok=" + ok); } } EOF #some data in src/main/resources/some_file_outside_scm cat >src/main/resources/some_file_outside_scm <<EOF 123 456 EOF #file src/main/resources/.gitignore cat >src/main/resources/.gitignore <<EOF some_file_outside_scm EOF #.gitignore in the project root cat >.gitignore <<EOF target deploy EOF git init . git add pom.xml git add src/main/java/Main.java git commit -m "first commit" #The test case can be tested with these commands mvn package echo !!!!!!!!!!!!!!!!! echo contents of the packaged jar jar tf target/artifact-0.0.1-SNAPSHOT.jar #The file 'some_file_outside_scm' is packaged into jar. echo !!!!!!!!!!!!!!!!! echo after mvn package java -cp target/artifact-0.0.1-SNAPSHOT.jar Main # ok=true echo !!!!!!!!!!!!!!!!! mvn release:prepare mvn release:perform echo !!!!!!!!!!!!!!!!! echo but after mvn release java -cp deploy/com/domain/artifact/0.0.1/artifact-0.0.1.jar Main # ok=false #the file is not included in the release jar echo !!!!!!!!!!!!!!!!! echo contents of the release jar jar tf deploy/com/domain/artifact/0.0.1/artifact-0.0.1.jar

Answer1:

If you are not putting the resources into SCM, you can't release them as part of this project, as mentioned by others.

You might try moving the resources into a separate project and using maven-remote-resources-plugin:bundle to build a resource bundle (jar). Any time you change a resource in that project you would need to manually bump the version number in your POM and do a mvn deploy to get the changes into your artifact repo.

Then, in your current project, you use maven-remote-resources-plugin:process to retrieve the resources and put them in the proper location in your artifact before it is built. process is bound to the generate-resources phase by default; adjust this to meet your needs.

Answer2:

Resources must be in your SCM, cause they are part of your project. Otherwise your project will not work whatever resources these are. So you don't put them under version control into src/main/resources as the rest project so they will never been packaged into the jar.

Answer3:

The release-plugin activates during release:perform the profile release-perform. You can use the resource-plugin for that profile to copy your resources.

Recommend

  • Count values that satisfy a constraint and return 0 for those that don't satisfy it in SPARQL
  • Show generated SQL in toplink in eclipse
  • Error: Wrapper cannot find servlet class VendorRegistration or a class it depends on
  • Select an attribute with Xpath in a XML with namespace using Powershell
  • Xpath how to get element by index AND attribute
  • Spring custom user details service null pointer exception
  • After switching from Spring Boot 1.2.8 to 1.3.2 application magically stops working
  • SessionInformation expiration doesn't lead to user log out from system
  • Reading contents of a managed bean with reflection in a JSF application
  • Savon soap body problem
  • Grails 3 - How to publish to Artifactory
  • Fill SVG path with a background-image without knowing height&width
  • Filtering SPARQL results by day and month
  • How to call BeanFactoryPostProcessor.postProcessBeanFactory method when use Spring with XML configur
  • how to ignore xml namespaces?
  • Separate ID and Class for JS and CSS
  • Should a web service response include empty values?
  • Feature detection of foreignObject in SVG
  • XSD with multi occurrences unordered
  • “mvn clean generate-source” could not resolve dependencies
  • Using Laravel 5.4 pusher
  • How to convert SOAP response with xsi values to json in WSO2esb
  • Oledb connection string for excel files
  • Jetty 9 HashLoginService
  • Read a local file using javascript
  • Exception “firebase.functions() takes … no argument …” when specifying a region for a Cloud Function
  • Jetty Server not starting: Unable to establish loopback connection
  • ImageMagick, replace semi-transparent white with opaque white
  • The plugin 'org.apache.maven.plugins:maven-jboss-as-plugin' does not exist or no valid ver
  • Highlight one bar in a series in highcharts?
  • Cannot connect to cassandra from Spark
  • Optimizing database types to compact database (SQLite)
  • Counter field in MS Access, how to generate?
  • Cross-Platform Protobuf Serialization
  • Alternatives to the OPTIONAL fallback SPARQL pattern?
  • Do I've to free mysql result after storing it?
  • Calling of Constructors in a Java
  • Arrays break string types in Julia
  • PHP: When would you need the self:: keyword?
  • Turn off referential integrity in Derby? is it possible?