为了正确install和deploy额外的神器(由编译生成的文件,通常也是继其版本和有关项目成果的连贯部分),你需要附加它的构建,以便Maven将其作为其结果的正式交付处理。
要将文件附加到构建,可以使用build-helper-maven-plugin。
下面是它的usage页的样本代码片段:
org.codehaus.mojo
build-helper-maven-plugin
1.12
attach-artifacts
package
attach-artifact
the-generated-file
extension of your file
optional
您应该将上述负责文件的生成插件之后的声明配置,即,该文件应该存在你的时候尝试将其附加到构建。查看file配置元素,在这里您应该指定文件,例如target\myfile.zip。在这种情况下,它将在package阶段附加,以便install和deploy阶段在处理期间将其考虑在内。
调用当
mvn clean install
然后你会看到作为构建输出的一部分:
[INFO] --- build-helper-maven-plugin:1.12:attach-artifact (attach-artifacts) @ zip-example ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ zip-example ---
[INFO] Installing C:\data\eclipse-workspace\zip-example\target\zip-example-0.0.1-SNAPSHOT.jar to c:\data\m2\repository\com\sample\zip-example\0.0.1-SNAPSHOT\zip-example-0.0.1-SNAPSHOT.jar
[INFO] Installing C:\data\eclipse-workspace\zip-example\pom.xml to c:\data\m2\repository\com\sample\zip-example\0.0.1-SNAPSHOT\zip-example-0.0.1-SNAPSHOT.pom
[INFO] Installing C:\data\eclipse-workspace\zip-example\sample.zip to c:\data\m2\repository\com\sample\zip-example\0.0.1-SNAPSHOT\zip-example-0.0.1-SNAPSHOT-optional.zip
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
注:sample.zip实际上是复制到m2的本地库zip-example-0.0.1-SNAPSHOT-optional.zip,因此根据改名项目配置(artifactId,version,classifier)。