Search code examples
spring-bootgradlegroovythymeleaf

thymeleaf-spring4:jar could not find artifact - gradle intelijj


I'm trying to build a simple application, using gradle, groovy, and spring-boot framework with this code:

@Grab("thymeleaf-spring4")

@Controller
class ViewBasedApp {
    def chapters = ["Quick Start With Groovy",
                    "Quick Start With Java",
                    "Debugging and Managing Your App",
                    "Data Access with Spring Boot",
                    "Securing Your App"]
    @RequestMapping("/")
    def home(@RequestParam(value="name", defaultValue="World") String n) {
        new ModelAndView("home")
                .addObject("name", n)
                .addObject("chapters", chapters)
    }
}

This is my build.gradle file:

group 'LoginApp'
version '1.0-SNAPSHOT'

apply plugin: 'groovy'

repositories {
    mavenCentral()
}

dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.3.11'
    testCompile group: 'junit', name: 'junit', version: '4.12'

    compile("org.springframework.boot:spring-boot-starter-web")
    //compile("org.thymeleaf:thymeleaf-spring4") //first try
   // compile("nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect") //first try
    compile 'org.springframework:spring-webmvc:3.0.0.RELEASE'

    // https://mvnrepository.com/artifact/org.thymeleaf/thymeleaf-spring4 //secound try
    compile group: 'org.thymeleaf', name: 'thymeleaf-spring4', version: '3.0.0.RELEASE'
   // compile group: 'org.thymeleaf', name: 'thymeleaf-spring4', version: '4.1.6.RELEASE' //third try
}

html file:

<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Learning Spring Boot - Chapter 1</title>
</head>
<body>
<p th:text="'Hello, ' + ${name}"></p>
<ol>
    <li th:each="chapter : ${chapters}" th:text="${chapter}"></li>
</ol>
</body>
</html>

To launch my app I using spring boot CLI. When I have been using "spring run" in command prompt, I always have got the same error: Could not find artifact :thymeleaf-spring4:jar: in local (file:/C:/Users/kubas/repository).

I have tried to add "thymeleaf-spring4.jar" - downloaded from maven page, to folder "repository" and nothing, always the same error.

Can anybody suggest on this?


Solution

  • I resolved this issue. I have used .html file and this is the way how I use this file in my Controller Class:

    @RestController
    class LoginServiceApplication {
    
        @RequestMapping("/")
        String home() {
            def htmlContent = new File("F:\\APKA_W_SPRINGU\\Spring-apps-master\\AppWithLoginPage\\LoginService\\src\\main\\resources\\templates\\index.html").text
    
            htmlContent
        }
    }
    

    For the first question - all I had have to do was a run main class in intelijj using button run (Class must not contain @Grab annotation!), before I resolved this problem I was using spring CLI and that was a problem. Now everything works fine.