Gradle相当于maven-dependency-plugin [英] Gradle equivalent of maven-dependency-plugin
问题描述
我的根本问题是,当为我的控制器和Freemarker视图运行基于spring-test的测试时,我需要在WEB-INF / lib文件夹中包含所有taglibs,否则freemarker在测试期间不会找到它们。我用以下的maven配置解决了这个问题。在运行测试之前,它实际上会将taglibs jar复制到src / main / webapp / WEB-INF / lib文件夹中。我不想清除此文件夹,因为在为IDE运行此测试时问题相同。
My root problem is that when running "spring-test"-based tests for my controllers and Freemarker views I need to have all taglibs inside WEB-INF/lib folder - otherwise freemarker will not find them during tests. I solved this issue with the following piece of maven configuration. It actually copies taglibs jars to src/main/webapp/WEB-INF/lib folder before running tests. I don't want to clear this folder since the problem is the same when running this test for the IDE.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.3</version>
<executions>
<!-- Freemaarker requires that all taglibs should reside in WEB-INF/lib folder -->
<execution>
<id>tests</id>
<phase>test-compile</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/src/main/webapp/WEB-INF/lib/</outputDirectory>
<artifactItems>
<artifactItem>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>${spring.security.version}</version>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
现在我将我的项目迁移到gradle。我怎么才能用gradle实现同样的功能?
Now I'm migrating my project to gradle. How can I achieve the same with gradle?
推荐答案
以下是我如何解决这个问题(与maven实际上相同):
Here is how I solved this problem (the same as in maven actually):
为依赖关系添加另一个配置:
Add another configuration for dependencies:
configurations{
taglibs { transitive = false }
}
为此配置添加所需的依赖项: p>
Add needed dependency to this configuration:
dependencies {
...
taglibs "org.springframework.security:spring-security-taglibs:$springSecurityVersion"
...
}
添加gradle代码以复制这些依赖关系到所需的文件夹:
Add gradle code to copy these dependencies to required folder:
task copytaglibs << {
copy {
from configurations.taglibs
into 'src/main/webapp/WEB-INF/lib'
}
}
compileTestJava{
dependsOn copytaglibs
}
就是这样。
这篇关于Gradle相当于maven-dependency-plugin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!