【发布时间】:2018-10-25 02:57:01
【问题描述】:
我的build.gradle 中有以下依赖项:
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 Publishing 插件发布我的库时,它包括 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配置中的依赖项添加到您的 build.gradle 中其他位置的compile配置中。需要查看更多的 build.gradle。还有为什么你有一个antlr配置? -
当然,这是 build.grade:github.com/graphql-java/graphql-java/blob/v2.1.0/build.gradle。我有一个
antlr配置,因为我使用的是Gradle ANTLR plugin -
@RaGe:
./gradlew generatePomFileForGraphqlJavaPublication在build/publications/graphqlJava/pom-default.xml中生成pom -
antlr 插件是doing internally,我有点指责你的所作所为。肯定会起作用的方法是编写一个任务以在生成的 xml 中啜饮并删除有问题的部分。甚至可以在发布部分使用
pom.withxml。 -
antlr 插件应该将
antlr配置添加到compileOnly而不是compile,这将解决所有这些问题。 copileOnly 依赖项不会进入 pom。另外:想知道您是否可以从构建脚本中覆盖插件正在执行的操作。
标签: gradle antlr build.gradle antlr4