Gradle equivalent of maven-dependency-plugin

大憨熊 提交于 2020-01-01 02:34:18

问题


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>

Now I'm migrating my project to gradle. How can I achieve the same with gradle?


回答1:


Here is how I solved this problem (the same as in maven actually):

Add another configuration for dependencies:

configurations{ 
     taglibs { transitive = false }
}

Add needed dependency to this configuration:

dependencies {
    ...
    taglibs "org.springframework.security:spring-security-taglibs:$springSecurityVersion"
    ...
}

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
}

This is it.



来源:https://stackoverflow.com/questions/16636702/gradle-equivalent-of-maven-dependency-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!