使用 Gradle 为 Eclipse 构建项目时,如何从构建路径中排除包?
文档中描述了一些示例: http://gradle.org/docs/current/dsl/org.gradle.plugins.ide.eclipse.model.EclipseClasspath.html
eclipse {
//if you want parts of paths in resulting file to be replaced by variables (files):
pathVariables 'GRADLE_HOME': file('/best/software/gradle'), 'TOMCAT_HOME': file('../tomcat')
classpath {
//you can tweak the classpath of the eclipse project by adding extra configurations:
plusConfigurations += configurations.provided
//you can also remove configurations from the classpath:
minusConfigurations += configurations.someBoringConfig
//if you don't want some classpath entries 'exported' in eclipse
noExportConfigurations += configurations.provided
//if you want to append extra containers:
containers 'someFriendlyContainer', 'andYetAnotherContainer'
//customizing the classes output directory:
defaultOutputDir = file('build-eclipse')
//default settings for dependencies sources/javadoc download:
downloadSources = true
downloadJavadoc = false
}
}
如果有人仍然遇到这个问题,尽管依赖项被声明为runtimeOnly,STS仍然坚持将其放在编译类路径上。这是在 Gradle 版本 8.7 和 STS 版本 4.22 中测试的解决方案:
configurations {
// Define a custom configuration for the dependency
excludeFromEclipse
}
dependencies {
// Add the dependency to the custom configuration
excludeFromEclipse 'group:artifact:version'
}
eclipse {
classpath {
// Exclude the custom configuration from the Eclipse classpath
minusConfigurations += [configurations.excludeFromEclipse]
}
}