我试图将Velocity与Gradle构建器连接起来。所以我在IntelliJ中创建了一个Gradle项目,将Gradle-Velocity-Plugin放入项目目录,导入Velocity jar并创建以下文件:
的的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");
}
}
}
现在,当我执行gradle tasks
时,一切都很好,但是当我执行gradle assemble
时,我得到错误,即速度包不存在。
你们有谁知道如何解决这个问题?
谢谢。