Java:使用Velocity连接Gradle

时间:2017-05-31 10:17:18

标签: java intellij-idea gradle velocity

我试图将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时,我得到错误,即速度包不存在。

你们有谁知道如何解决这个问题?
谢谢。

0 个答案:

没有答案