我有以下依赖我build.gradle
:如何从Gradle Maven Publishing插件构建的POM中排除依赖项?
dependencies {
compile 'org.antlr:antlr4-runtime:4.5.1'
compile 'org.slf4j:slf4j-api:1.7.12'
antlr "org.antlr:antlr4:4.5.1"
testCompile group: 'junit', name: 'junit', version: '4.11'
testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
testCompile 'org.codehaus.groovy:groovy-all:2.4.4'
testCompile 'cglib:cglib-nodep:3.1'
testCompile 'org.objenesis:objenesis:2.1'
}
当我使用Maven发布插件发布我的图书馆,它包括了ANTLR运行时和编译时JAR文件作为generated POM依赖关系:
<dependencies>
<dependency> <!-- runtime artifact -->
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>4.5.1</version>
<scope>runtime</scope>
</dependency>
<dependency> <!-- compile time artifact, should not be included -->
<groupId>org.antlr</groupId>
<artifactId>antlr4</artifactId>
<version>4.5.1</version>
<scope>runtime</scope>
</dependency>
</dependencies>
我只希望将运行时库包含在此POM中。
罪魁祸首是antlr
依赖项:如果我删除此行,生成的POM不具有编译时间依赖性。但是,构建失败。
清楚你从'antlr'配置将依赖于你的'compile'配置别的地方在你的build.gradle。需要看到更多的build.gradle。另外为什么你有一个'antlr'配置? – RaGe
当然,这里是build.grade:https://github.com/graphql-java/graphql-java/blob/v2.1.0/build.gradle。我有一个'antlr'配置,因为我使用了[Gradle ANTLR插件](https://docs.gradle.org/current/userguide/antlr_plugin.html) –
@RaGe:'./gradlew generatePomFileForGraphqlJavaPublication'生成了pom 'build/publications/graphqlJava/pom-default.xml' –