将其他源集添加到 Gretty 类路径

Add additional source set to Gretty classpath

我的项目包含一个 jar 和一个 war 模块。 jar 模块包含源集 maingenerated.

我的 jar 模块 gradle.build 定义了如下所列的源集:

sourceSets {
    generated
    main {
        compileClasspath += sourceSets.generated.output  // adds the sourceSet to the compileClassPath
        runtimeClasspath += sourceSets.generated.output  // adds the sourceSet to the runtimeClasspath
    }
}

并将两个源集的输出放入 jar。

jar {
    from sourceSets.generated.output
    from sourceSets.main.output
}

在我的 war 模块中,我想在构建中使用 Gretty 运行 它。 build.gradle 文件如下所示。

apply plugin: 'war'
apply from: "${rootDir}/gradle/gretty.gradle"

gretty {
    // supported values:
    // 'jetty7', 'jetty8', 'jetty9', 'tomcat7', 'tomcat8'
    servletContainer = 'tomcat8'

    httpPort = 8081
    contextPath = '/wbc'
    realm 'wbc-realm'
    realmConfigFile 'tomcat-users.xml'
}

dependencies {
    compile project(':interfaces')

    compile "org.atmosphere:atmosphere-runtime:${atmosphereVersion}"
    compile "org.springframework:spring-web:${springVersion}"
    compile "javax.servlet:javax.servlet-api:${servletVersion}"

    runtime "org.slf4j:slf4j-log4j12:${slf4jVersion}"
    runtime "log4j:log4j:1.2.17"
}

每当我使用 gradle --daemon clean appRun 启动 Gretty 时,由于 ClassNotFoundException,Gretty 无法启动 Tomcat。 class 位于我的 jar 模块的 generated 源集中。我如何告诉 gretty 将其添加到 class 路径?

尝试将生成的输出目录添加到 gretty classPath:

gretty {
  ...
  sourceSets.generated.output.each { classPath it }
}