Maven:库的开发和发布版本
我有一个由 3 个库组成的项目 - 我们称它们为 1) BABY、2) CHILD 和 3) ADULT。库“CHILD”取决于“BABY”,“ADULT”取决于“CHILD”。
我想要做的是生成:
- 具有所有(传递)依赖项的开发版本
- 为每个库创建独立 JAR 的生产版本(嵌入依赖项)
我有一个配置文件 dev
和一个配置文件已经发布,并且我知道如何使用 ProGuard 生成 JAR。
问题是如何告诉 Maven 将所有依赖项保留在 dev
中,并在 生产
中忽略它们(可选/提供)?
I have a project consisting of 3 libraries - let's call them 1) BABY, 2) CHILD and 3) ADULT. Lib "CHILD" depends on "BABY" and "ADULT" depends on "CHILD".
What I want to do is produce:
- a dev version that has all the (transitive) dependencies
- a production version that creates a standalone JAR for each library (embedding the dependencies)
I have a profile dev
and a profile release
already, and I know how to use ProGuard to generate the JAR.
The question is how to tell Maven to keep all dependencies in dev
and ignore them (optional/provided) in production
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要在开发部署时拥有不同的依赖项,可以使用 Maven 配置文件。
http://maven.apache.org/guides/introduction/introduction- to-profiles.html
因此,在开发时,您会使用类似
mvn -Pdevcompile
当您说“独立 jar”时,听起来您的意思是一个将所有依赖项合并到其中的 jar。
如何使用以下命令创建具有依赖项的可执行 JAR Maven?
或 http://maven.apache.org/plugins/maven-assemble-plugin/
To have different dependencies when you develop to deployment you could use maven profiles.
http://maven.apache.org/guides/introduction/introduction-to-profiles.html
So when developing you would use something like
mvn -Pdev compile
When you say "standalone jar" it sounds like you mean a jar with all dependencies merged into it.
How can I create an executable JAR with dependencies using Maven?
or http://maven.apache.org/plugins/maven-assembly-plugin/
这是我最终使用的:
父 POM 定义了一个配置文件
release
,它配置proguard 插件
(打包一个大 JAR)和安装插件< /code> (将发布工件放入存储库中)。
lib-baby POM 仅调用部分中的 2 个插件。
lib-child POM 还指定了一个
dev
配置文件,其中定义了对lib-baby
的依赖关系。在发布配置文件中,此依赖项有一个可选
标记,并包含在大 JAR 中。最后,默认运行时,会创建库
com.company.dev:lib-baby
和com.company.dev:lib-child
(包括它们的依赖项) 。当使用
-Prelease
运行时,会创建库com.company:lib-baby
和com.company:lib-child
(独立库 [WITHOUT任何依赖项]) - 唯一的副作用是默认工件(.*dev)被覆盖:(parent:
lib-baby:
lib-child:< /强>
Here is what I used eventually:
The parent POM defines a profile
release
that configurates theproguard plugin
(crates one big JAR) and theinstall plugin
(places the release artifact in the repo).The lib-baby POM simply calls the 2 plugins in the
<build>
section.The lib-child POM additionally specifies a
dev
profile where the dependency tolib-baby
is defined. Within the release profile this dependency has anoptional
tag and is included in the big JAR.In the end when run by default, the libs
com.company.dev:lib-baby
andcom.company.dev:lib-child
are created (included their dependencies).When run with
-Prelease
the libscom.company:lib-baby
andcom.company:lib-child
are created (standalone libs [WITHOUT any dependencies]) - only side effect is that the default artifacts (.*dev) are overwritten :(parent:
lib-baby:
lib-child: