Maven 配置文件相当于 Gradle [英] Maven profiles equivalent of Gradle

查看:42
本文介绍了Maven 配置文件相当于 Gradle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的 Spring Boot 项目构建中实现一个简单的场景:包括/排除依赖项以及根据环境打包 war 或 jar.

I'm trying to achieve a simple scenario in my spring boot project build: including / excluding dependencies and packaging war or jar depending on the environment.

例如,对于环境dev包括devtools和package jar,对于prod package war等

So for example, for the environment dev include devtools and package jar, for prod package war etc.

我知道它不再是基于 XML 的配置,我基本上可以在 build.gradle 中编写 if 语句,但是否有推荐的方法来实现这一点?

I know it is not XML based configuration anymore and I can basically write if statements in my build.gradle but is there a recommended way of achieving this?

我可以声明一些常见的依赖项并在单个文件中引用它们而不是创建多个构建文件吗?

Can I declare some common dependencies and refer them in a single file instead of creating multiple build files?

是否有根据构建目标环境更改构建配置的最佳实践?

Is there a best practice changing build configuration based on the build target environment?

推荐答案

ext {
    devDependencies = ['org.foo:dep1:1.0', 'org.foo:dep2:1.0']
    prodDependencies = ['org.foo:dep3:1.0', 'org.foo:dep4:1.0']
    isProd = System.properties['env'] == 'prod'
    isDev = System.properties['env'] == 'dev'
}

apply plugin: 'java'

dependencies {
    compile 'org.foo:common:1.0'
    if (isProd) {
       compile prodDependencies
    }
    if (isDev) {
       compile devDependencies
    }
}

if (isDev) tasks.withType(War).all { it.enabled = false }

这篇关于Maven 配置文件相当于 Gradle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆