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?
You can't use a Maven plugin as-is in Gradle; you'll have to port it to a Gradle plugin. How difficult this is depends on how many Maven APIs the plugin is using. Another strategy might be to call into Maven via Gradle's Exec task.
To convert Maven to Gradle, the only step is to run gradle init in the directory containing the POM. This will convert the Maven build to a Gradle build, generating a settings. gradle file and one or more build. gradle files.
you can call gradle publishToLocalRepo in its folder, you will find in the build/publications/maven subfolder, a file called pom-default. xml. Also, the built JAR together with the POM will be in your Maven local repo.
Gradle's performance advantages A Gradle task is the equivalent of a Maven goal. Just a unit of work to get executed in the build. Gradle keeps track of each task's inputs and outputs. Only when these change does the task get rerun.
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(type: Copy) {
from configurations.taglibs
into 'src/main/webapp/WEB-INF/lib'
}
compileTestJava {
dependsOn copytaglibs
}
This is it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With