Maven或Gradle构建类型/变体 [英] Maven or Gradle build types/variants

查看:222
本文介绍了Maven或Gradle构建类型/变体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android Gradle插件增加了对构建类型和构建变体的支持,使您可以在构建步骤中选择要构建的应用程序的版本(例如,调试版或发布版)。



这是Gradle项目的一个非常有用的功能,因为您可以拥有两个版本的应用程序,这些版本在某些情况下可能会有所不同,或者具有不同的配置文件或属性,具体取决于构建类型。



现在,我的问题是:是否有类似于Maven或Gradle的Android Java项目的特性/实现?我正在寻找Java Web应用程序,但我认为这个问题可能有更大的目标。

解决方案

追查没有模糊的答案,这是来自 Luke Daley(Gradleware Engineer)的官方回应:


这是我们正在积极努力的事情。我们正在努力以一般方式支持
变体的概念,以便在各个域名之间实现
一致的方法。这是一个深刻而深刻的变化,虽然
,所以涉及很多。



您可以期待看到在Gradle 2.5和$ b中推出的方面$ b。

稍后编辑:我终于可以在JavaEE上运行了通过使用SourceSets代替Build Types&变种。考虑到SourceSets已经存在了很长一段时间,显然你可能早在几年前就已经完成了......但是即使是gradle工程师也没有能够正确地解释如何这样做......



无论如何,请查看下面的 build.gradle 代码,我们在两个SourceSets中使用相同的输出目录,然后指定WAR插件的位置来自:

  apply plugin:'war'

sourceSets {
main {
output.resourcesDir ='build / resources'
output.classesDir ='build / classes'
}
debug {
java {
compileClasspath + = main.output
runtimeClasspath + = main.output
}
output.resourcesDir ='build / resources'
output.classesDir ='build / classes'
}
}

任务assembleDebugWar(类型:War){源自sourceSets.debug.output的

archiveNameROOT.w ar
}

任务assembleReleaseWar(类型:War){$ b $ from sourceSets.main.output
archiveNameROOT.war
}


The Android Gradle plugin adds support for build types and build variants, which let you select which version of your application you want to build at the build step (ex, debug or release).

This is a very useful feature for Gradle projects, as you can have 2 versions of your application that may behave differently in some situations, or have different configuration files or properties depending on the type of build.

Now, my question is: is there a similar feature/implementation for non-Android Java projects from Maven or Gradle? I am looking specifically for Java web apps, but I presume the question may have a larger target as well.

解决方案

Cutting it to the chase without vague answers, here is the official response from Luke Daley (Gradleware Engineer) on this matter:

It is something we are actively working on. We are working to support the notion of variants in a general way, so that there will be a consistent approach across domains. It's a deep, deep, change though so there is a lot involved.

You can expect to see aspects of this rolling out in Gradle 2.5 and on.

Later Edit: I've finally been able to get this working on a JavaEE webapp project by using SourceSets instead of Build Types & Variants. Considering that SourceSets have been around for a very very long time, apparently you could've done this ages ago... But not even gradle engineers were able to properly explain how to do so...

Anyhow, check out the build.gradle code below, where we use the same output directory for both SourceSets, then specify the location for the WAR plugin to build from:

apply plugin: 'war'

sourceSets {
    main {
        output.resourcesDir = 'build/resources'
        output.classesDir   = 'build/classes'
    }
    debug {
        java {
            compileClasspath += main.output
            runtimeClasspath += main.output
        }
        output.resourcesDir = 'build/resources'
        output.classesDir   = 'build/classes'
    }
}

task assembleDebugWar(type: War) {
    from sourceSets.debug.output
    archiveName "ROOT.war"
}

task assembleReleaseWar(type: War) {
    from sourceSets.main.output
    archiveName "ROOT.war"
}

这篇关于Maven或Gradle构建类型/变体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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