为 Vaadin 应用程序构建多个工件 [Gradle]

Building mutiple Artifacts for Vaadin-Application [Gradle]

我目前正在使用 gradle vaadin-plugin 开发一个 Vaadin 8 项目。

项目中有3个SourceSets main,a,b。后两者排除了一些观点和特征。是否可以通过 gradle 为每个 sourceSet 构建 3 个 Artifcat。我尝试修改 war 任务,但这破坏了视图。

conf{
    aCompile.extendsFrom compile
    aRuntime.extendsFrom runtime

    bCompile.extendsFrom compile
    bRuntime.extendsFrom runtime
}
 sourceSets {
    main {
        java {
            srcDirs = ['src/main/java', 'src/main/generated']
        }
    }
    a{
        java {
            srcDirs = ['src/main/java', 'src/main/generated']
            exclude 'com/exmaple/features/b'
            exclude 'com/exmaple/views/b'
        }

        compileClasspath += main.output
        runtimeClasspath += main.output

        output.resourcesDir = 'build/resources/main'
        output.classesDir = 'build/classes/java/main'
    }
    b{
        java {
            srcDirs = ['src/main/java', 'src/main/generated']
            exclude 'com/exmaple/features/a'
            exclude 'com/exmaple/views/a'
        }
        compileClasspath += main.output
        runtimeClasspath += main.output

        output.resourcesDir = 'build/resources/main'
        output.classesDir = 'build/classes/java/main'
    }
}
task aWar(type: War) {
    appendix = "a"
    from sourceSets.a.output
}

task bWar(type: War) {
    appendix = "b"
    from sourceSets.b.output
}

https://docs.gradle.org/current/userguide/artifact_management.html#sec:declaring_artifacts 开始,您应该能够为每个源集声明一个工件。

在你的情况下,它看起来像这样:

task aWar(type: War, dependsOn: classes) {
  baseName = 'a.war'
  classpath = project.configurations.aRuntime
}

task bWar(type: War, dependsOn: classes) {
  baseName = 'b.war'
  classpath = project.configurations.bRuntime
}

artifacts {
   archives aWar, bWar
}

WAR 任务还允许您 include/exclude 类 使用正则表达式。在 https://docs.gradle.org/current/dsl/org.gradle.api.tasks.bundling.War.html

查看更多