我的问题是关于与Maven做释放时,包含在jar文件资源。
我使用Maven来构建我的项目,当我运行
$ mvn package
资源包括在输出罐子。 但是,当我运行
$ mvn release:prepare
$ mvn release:perform
这些资源不包含在释放罐子。
资源位于Maven的默认目录src/main/resources
,但它们是外源控制(通过忽略.gitignore
)。 从行家进行的输出我意识到行家做的git结帐不同的文件夹和资源不会被复制到该文件夹。 这就是为什么maven的版本插件不打包发布罐子。
我的问题是什么是应对这种情况的最好方法是什么?
请在释放过程中的资源文件夹中的符号链接? 怎么样?
复制的资源? 怎么样?
或将资源投入到供应链管理是让他们在发布的软件包中提供的唯一途径?
我准备小测试用例此:
#!/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