有没有办法复制Maven的attachClasses war插件Gradle中的功能? [英] Is There a Way to Replication Maven attachClasses war Plugin Functionality in Gradle?
问题描述
使用Maven,我们正在使用以下方法从WAR文件中分离出类:
Using Maven we are currently separating out classes from a WAR file using:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven-war-plugin.version}</version>
<configuration>
<packagingExcludes>WEB-INF/web.xml</packagingExcludes>
<attachClasses>true</attachClasses>
<filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
</configuration>
</plugin>
是否可以在Gradle中复制此功能?我们的目标是在主要战争工件旁边发布.jar中的类:
Is it possible to replicate this functionality in Gradle? The goal is to publish just the classes in a .jar alongside the primary war artifact:
ghc-templates-2.29-javadoc.jar 14-Jan-2014 15:19 112.43 KB
ghc-templates-2.29-sources.jar 14-Jan-2014 15:19 12.81 KB
ghc-templates-2.29.war 14-Jan-2014 15:19 6.05 MB
ghc-templates-2.29-classes.jar 14-Jan-2014 15:19 23.95 KB
推荐答案
是的,只需运行 jar
任务即可。由于 War
插件应用了 Java
插件,所以你可以像普通Java项目一样获得所有常规任务。但是,在运行 assemble
时,缺省情况下,该任务不会包含在依赖关系图中(请参阅 grade docs )。要解决这个问题,只需添加:
Yes, just run jar
task. Since the War
plugin applies the Java
plugin you get all the regular tasks you would as if it were a normal java project. However, that task is not included in the dependency graph by default when running assemble
(see the grade docs). To fix this simply add:
assemble {
dependsOn jar
}
另外,按照上面的示例,如果您想将自定义分类添加到jar中,您可以这样做:
Also, as per your example above, if you want to add a custom classifier to the jar you can do so:
jar {
classifier = 'classes'
}
这篇关于有没有办法复制Maven的attachClasses war插件Gradle中的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!