gpt4 book ai didi

java - 查询WAR插件的Gradle依赖关系

转载 作者:行者123 更新时间:2023-12-03 05:49:51 26 4
gpt4 key购买 nike

我是Gradle的新手。使用Gradle 3.5,我试图从Java项目创建一个war构建。以下是我的gradle文件内容。

apply plugin: 'war'

buildDir = "${rootProject.ext.buildGradle}/${project.name}"
def buildClassesDir = buildDir.getAbsolutePath() + '/classes/main'

configurations {
localLibraries
}

task copyNonJava(type: Copy, dependsOn: compileJava) {
from ('src/main/java') {
exclude '**/*.java'
include '**/*.properties'
}
from ('resources') {
include 'default_content.properties'
}

into buildClassesDir

includeEmptyDirs = false
}

task bundleJar (type: Jar, dependsOn: ['compileJava', 'copyNonJava']) {
baseName archivesBaseName
from buildClassesDir
}

task bundleWar (type: War, dependsOn: ['bundleJar']) {
baseName = project.name
from 'web'
webXml = file( 'resources/WEB-INF/web.xml' )
classpath = configurations.localLibraries
}

dependencies {
compile group: 'com.system', name: 'core', version: rootProject.version, changing: true
compile group: 'com.system', name: 'core-ui', version: rootProject.version, changing: true
compile group: 'com.persistence', name: 'persistence', version: '1.0'
compile group: 'com.surveys', name: 'survey', version: '1.0'

localLibraries fileTree("lib") {
exclude 'spring*'
}
}

当我生成war build时,它将jar文件添加到 WEB-INF/lib目录下。但是,除了那些jar文件之外,我还希望 com.system组中的jar文件和 bundleJar任务生成的jar文件。我该如何实现?

最佳答案

默认情况下,来自compile配置的库包含在classpath中,但是classpath = configurations.localLibraries覆盖默认值。

除了overriding the default classpath(classpath = ...有效表示setClasspath(...)),您可以append additional files to it:

task bundleWar (type: War, dependsOn: ['bundleJar']) {
baseName = project.name
from 'web'
webXml = file( 'resources/WEB-INF/web.xml' )
classpath configurations.localLibraries
classpath bundleJar.archivePath
}

关于java - 查询WAR插件的Gradle依赖关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48395772/

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