gpt4 book ai didi

java - 在 IntelliJ Java 应用程序中构建变体(产品风格)

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:26:23 25 4
gpt4 key购买 nike

是否可以在 IntelliJ 中为传统 Java 应用(而非 Android 项目)构建基于不同源集的变体?

我想使用 Android gradle 插件附带的 productFlavors 等功能,但用于传统的 Java 应用程序。

例子:

library_red -- HelloImpl.java
library_blue -- HelloImpl.java
library_common -- Hello.java

compiled library_blue -- Hello.class, HelloImpl.class
compiled library_red -- Hello.class, HelloImpl.class

最佳答案

答案是肯定的,但您将不得不使用新的 Gradle 软件模型,它正在孵化。这将是一条充满痛苦的道路,因为您将成为开拓者,因为我已经学会了将它用于 C/Cpp 项目。您的构建通常如下所示。

plugins {
id 'jvm-component'
id 'java-lang'
}

model {
buildTypes {
debug
release
}
flavors {
free
paid
}
components {
server(JvmLibrarySpec) {
sources {
java {
if (flavor == flavors.paid) {
// do something to your sources
}
if (builtType == buildTypes.debug) {
// do something for debuging
}
dependencies {
library 'core'
}
}
}
}

core(JvmLibrarySpec) {
dependencies {
library 'commons'
}
}

commons(JvmLibrarySpec) {
api {
dependencies {
library 'collections'
}
}
}

collections(JvmLibrarySpec)
}
}

引用:https://docs.gradle.org/current/userguide/java_software.html

关于java - 在 IntelliJ Java 应用程序中构建变体(产品风格),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35478176/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com