Thymeleaf fails on gradle build -


using spring-boot , thymeleaf build application. works fine in intellij, when build via "gradle clean build" errors.

here directory structure:

src  - generated  - main  -- java  -- resources  --- assets  ---- css/js  ---- templates  ----- *.html  -- webapp  - test  -- groovy  --- unit & integration tests here  -- resources  -- unit 

here gradle file:

apply plugin: 'java' apply plugin: 'groovy' apply plugin: 'idea' apply plugin: 'spring-boot' apply plugin: 'jacoco' apply plugin: 'war' apply plugin: 'maven'  def generatedresources = "$builddir/generated-resources/main"  configurations {     querydslapt }  buildscript {     repositories {         maven { url "http://repo.spring.io/libs-snapshot" }         mavenlocal()     }     dependencies {         classpath("org.springframework.boot:spring-boot-gradle-plugin:1.0.0.rc4")     } }   repositories {     mavencentral()     maven {url "http://repo.spring.io/libs-snapshot"}     maven {url 'http://repo.spring.io/milestone' } }  dependencies {     compile("org.springframework.boot:spring-boot-starter-web:1.0.0.release")     compile("org.springframework.boot:spring-boot-starter-data-jpa:1.0.1.release")     compile("org.springframework.boot:spring-boot:1.0.1.release")     compile("org.springframework:spring-orm:4.0.0.rc1")     compile("org.hibernate:hibernate-entitymanager:4.2.1.final")     compile("com.h2database:h2:1.3.172")     compile("joda-time:joda-time:2.3")     compile("org.thymeleaf:thymeleaf-spring4")     compile("org.codehaus.groovy.modules.http-builder:http-builder:0.7.1")     compile('org.codehaus.groovy:groovy-all:2.2.1')     compile('org.jadira.usertype:usertype.jodatime:2.0.1')     compile('com.mysema.maven:maven-apt-plugin:1.0.2')     compile('com.mysema.querydsl:querydsl-apt:3.3.2')     compile('com.mysema.querydsl:querydsl-jpa:3.3.2')      querydslapt "com.mysema.querydsl:querydsl-apt:3.3.2"     testcompile('org.spockframework:spock-core:0.7-groovy-2.0') {         exclude group: 'org.codehaus.groovy', module: 'groovy-all'     }     testcompile('org.codehaus.groovy.modules.http-builder:http-builder:0.7+')     testcompile("junit:junit") }  jacocotestreport {     group = "reporting"     description = "generate jacoco coverage reports after running tests." }  sourcesets {      generated {         java {             srcdirs = ['src/main/generated']         }     }     main {         //let's register output folder on main sourceset:     output.dir(generated, builtby: 'generatequerydsl')         java {             srcdirs = []         }         groovy {             srcdirs = ['src/main/groovy', 'src/main/java']         }         resources {             srcdirs = ['src/main/resources']         }          output.resourcesdir = "build/classes/main"     }      test {         java {             srcdirs = []         }         groovy {             srcdirs = ['src/test/groovy', 'src/test/java']         }         resources {             srcdirs = ['src/test/resources']         }          output.resourcesdir = "build/classes/test"     } }   task generatequerydsl(type: javacompile, group: 'build', description: 'generates querydsl query types') {     source = sourcesets.main.java     classpath = configurations.compile + configurations.querydslapt     options.compilerargs = [             "-proc:only",             "-processor", "com.mysema.query.apt.jpa.jpaannotationprocessor"     ]     destinationdir = sourcesets.generated.java.srcdirs.iterator().next() }  compilejava {     dependson generatequerydsl     source generatequerydsl.destinationdir }  compilegeneratedjava {     dependson generatequerydsl     options.warnings = false     classpath += sourcesets.main.runtimeclasspath }  clean {     delete sourcesets.generated.java.srcdirs }  idea {     module {         sourcedirs += file('src/main/generated')     } }  task wrapper(type: wrapper) {     gradleversion = '1.11' } 

i have ui configured such:

@configuration public class mvcconfig extends webmvcconfigureradapter { ...     @override     public void addviewcontrollers(viewcontrollerregistry registry) {         registry.addviewcontroller( "/home" ).setviewname( "index" );      ...     }   // removed try , find css/js/images //@override //public void addresourcehandlers(resourcehandlerregistry registry) { //    registry.addresourcehandler( "/resources/**" ).addresourcelocations( "/resources/" ); //}        ... } 

here example test:

@springapplicationconfiguration class treasurystatusevaluatortest extends specification {      @shared     def configurableapplicationcontext context      @shared     private statusrepository statusrepository      void setupspec() {         future future = executors.newsinglethreadexecutor().submit(                 new callable() {                     @override                     public configurableapplicationcontext call() throws exception {                         return (configurableapplicationcontext) springapplication.run(ofac.class)                     }                 })         context = future.get(60, timeunit.seconds)         treasurystatusevaluator = context.getbean(treasurystatusevaluator.class)         statusrepository = context.getbean(statusrepository.class)     }      void cleanupspec() {         if (context != null) {             context.close()         }     } ... } 

here typical html page:

<head>     <meta http-equiv="content-type" content="text/html; charset=utf-8"/>     <meta name="viewport" content="width=device-width, initial-scale=1.0"/>     <meta name="description" content=""/>        <link href="/resources/static/css/bootstrap.css" rel="stylesheet"/>     <link href="/resources/static/css/bootstrap.min.css" rel="stylesheet"/>     <link href="/resources/static/css/bootstrap-responsive.css" rel="stylesheet"/>     <link href="/resources/static/css/bootstrap-responsive.min.css" rel="stylesheet"/>     <link href="/resources/static/css/ofac.css" rel="stylesheet"/>     <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet"/>      <!-- html5 shim, ie6-8 support of html5 elements -->     <!--[if lt ie 9]>     <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>     <![endif]--> </head> <body> <div id="wrap"> ...  <script src="/resources/static/js/libs/jquery.min.js"></script> <script src="/resources/static/js/libs/bootstrap/bootstrap.min.js"></script> </body> </html> 

these tests run within intellij or application well. when run tests command line, errors such as:

caused by: java.lang.illegalstateexception: cannot find template location: class path resource [templates/] (please add templates or check thymeleaf configuration) 

i see in spring-boot there issue directory structure thymeleaf: https://github.com/spring-projects/spring-boot/issues/424 , seem template directory required. not using templates, html.

update #1: moved html under src/main/resources/*

update #2: moved css/js/libs src/main/resources/static tried having them under src/main/static didn't work either

there 1.0.1.release of spring boot now, should using (and might fix problem). normally, though, wouldn't expect need thymeleaf configuration long put templates in "classpath:/templates" (those html files thymeleaf calls "templates"). can specify template location using spring.thymeleaf.prefix if want them somewhere else (see docs here).

if prefer configure thmyeleaf need use conventional bean name template resolver ("defaulttemplateresolver"), boot knows doing. details in thymeleafautoconfiguration - of features there explicitly called out in docs, 1 appears not be.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

c# - Unity IoC Lifetime per HttpRequest for UserStore -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -