Gradle产品风味"纯"gradle(不是android gradle)

sbo*_*sbo 6 java gradle

我想用gradle为不同的客户构建一个java库.在"纯粹"的gradle中有没有类似于android知道的产品风味?

谢谢.

Mic*_*bbs 1

答案是肯定的,但您将必须使用正在孵化的新 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)
    }
}
Run Code Online (Sandbox Code Playgroud)

参考资料: 1) Java 软件模型https://docs.gradle.org/current/userguide/java_software.html 2) 风格https://docs.gradle.org/current/userguide/native_software.html 注意:我不是确定 Java 软件模型对风味的支持有多好,我将进行一些测试并返回报告。

更新:这是可行的,但目前 JvmLibrarySpec 不支持。我将尝试发布更完整的答案,并举例说明如何执行自定义规范。