I'm trying to connect Velocity with Gradle builder. So I created a Gradle project in IntelliJ, put the Gradle-Velocity-Plugin into the project directory, imported the Velocity jar and created the following files:
build.gradle:
group 'xxxxx'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.5
repositories {
mavenCentral()
jcenter()
}
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'org.anarres.gradle:gradle-velocity-plugin:[1.0.0,)'
}
}
apply plugin: 'velocity'
jar {
manifest {
attributes 'Main-Class': 'test.HelloWorld'
}
}
HelloWorld.java:
package test;
import java.io.StringWriter;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
public class HelloWorld
{
public static void main(String[] args)
{
try {
VelocityEngine ve = new VelocityEngine();
ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
ve.init();
VelocityContext context = new VelocityContext();
context.put("name", "World");
Template t = ve.getTemplate( "helloworld.vm" );
StringWriter writer = new StringWriter();
t.merge( context, writer );
System.out.println( writer.toString() );
}
catch (Exception e) {
System.out.println("failed");
}
}
}
Now, when I execute gradle tasks, everything is fine, but when I execute gradle assemble, I get errors, that the velocity packages do not exist.
Does anyone of you got an idea how to fix this?
Thank you.