Use Spring Boot as a transitive dependency from common JAR with Gradle - java

I have a common library that is published as a jar to maven local, which is then used by a set of very thin client applications. These applications basically feed their own configuration to the common library and initializes themselves as Spring applications.
This common library uses spring boot and a bunch of other dependencies. My question is, is it possible for me to not define spring boot as a dependency in the applications, and simply use the common library's spring version as a transitive dependency in all the applications?
I feel like this should be possible, but when I tried doing it, the springframework.org.boot classes are not being resolved (eg: #SpringBootApplication annotation).
These are my build.gradle files:
build.gradle from the common library
plugins {
id 'java-library'
id 'maven-publish'
}
group 'com.my.group'
version '1.0-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenLocal()
}
publishing {
publications {
mavenJava(MavenPublication) {
groupId = 'com.my.group'
artifactId = 'common-lib'
version = '0-alpha.1'
from components.java
}
}
}
configurations {
springBom
compileOnly.extendsFrom(springBom)
annotationProcessor.extendsFrom(springBom)
implementation.extendsFrom(springBom)
}
dependencies {
springBom enforcedPlatform('org.springframework.boot:spring-boot-dependencies:2.3.5.RELEASE')
api 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.cloud:spring-cloud-aws-messaging'
annotationProcessor 'org.springframework.boot:spring-boot-autoconfigure-processor'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
// a few other non-spring dependencies
}
build.gradle from a sample application
plugins {
id 'java'
}
group = 'com.my.group'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenLocal()
}
dependencies {
implementation group: 'com.my.group', name: 'common-lib', version: '0-alpha.1'
}
Example application initialization
package com.my.group.Core;
// none of the below are resolved
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
#SpringBootApplication(scanBasePackages = {"com.my.group"})
public class ConsumerApplication implements ApplicationRunner {
#Autowired
Core core;
public ConsumerApplication() {
}
public static void main(String[] args) {
SpringApplication.run(ConsumerApplication.class, args);
}
#Override
public void run(ApplicationArguments args) {
try {
core.processEvents();
} catch (ConfigurationException | InitializationException e) {
e.printStackTrace();
}
}
}
If I add in the following dependencies to my applications, everything works as expected.
springBom enforcedPlatform('org.springframework.boot:spring-boot-dependencies:2.3.5.RELEASE')
implementation 'org.springframework.boot:spring-boot-starter'

I found the issue. I have not included api in the configurations and as a result, the application could not resolve the version. Fixed by updating the build.gradle in my common library like so:
configurations {
springBom
compileOnly.extendsFrom(springBom)
annotationProcessor.extendsFrom(springBom)
implementation.extendsFrom(springBom)
api.extendsFrom(springBom)
}

Related

Trying to implement cucumber.api.cli.Main.main()

I have tried to implement the 'cucumber.api.cli.Main' but I get the following error: "No backends were found. Please make sure you have a backend module on your CLASSPATH." Does this mean I am missing a dependency? My Gradle and java code is below.
java code
package cucumber;
import cucumber.api.cli.Main;
import java.io.PrintStream;
public class CucumberRunEngine {
public static void main(String[] args) {
try {
Main.main(
new String[]{
"CLASSPATH:src.main.groovy.cucumber.features.addDeal",
//"-t", "#Daily",
"-g", "cucumber.stepDefinitions",
"-p", "pretty",
"-p", "html:target/HTMLReports/report.html",
"-p", "junit:target/JUNITReports/report.xml",
"-p", "json:target/JSONReports/report.json",
"-m"
}
);
} catch (Exception e) {
PrintStream printer =System.out;
printer.println(e);
for (int element=0;element<e.getStackTrace().length;element++) {
printer.println(e.getStackTrace()[element]);
}
}
}
}
Gradle code
plugins {
id 'groovy'
id 'java-library'
id 'application'
id "se.thinkcode.cucumber-runner" version "0.0.8"
}
dependencies {
//Standard
api "org.codehaus.groovy:groovy-all:${groovyVersion}"
api "com.reuters:corejavalib:${coreJavaLibVersion}"
api "com.oracle:ojdbc7:${ojdbc7Version}"
implementation "commons-io:commons-io:${commonsIoVersion}"
implementation "commons-lang:commons-lang:${commonLangVersion}"
//JUnit
implementation "junit:junit:${jUnitVersion}"
// implementation("org.junit.platform:junit-platform-suite")
compileOnly "org.testng:testng:${testNGVersion}"
//Cucumber
compileOnly "io.cucumber:cucumber-java:${cucumberVersion}"
compileOnly "io.cucumber:cucumber-java8:${cucumberVersion}"
compileOnly "io.cucumber:cucumber-junit:${cucumberVersion}"
compileOnly "io.cucumber:cucumber-groovy:${cucumberGroovyVersion}"
compileOnly "io.cucumber:cucumber-gherkin:${cucumberVersion}"
compileOnly "io.cucumber:cucumber-jvm-groovy:${cucumberGroovyVersion}"
compileOnly "io.cucumber:cucumber-junit-platform-engine:${cucumberVersion}"
implementation "io.cucumber:cucumber-core:${cucumberVersion}"
}
application{
mainClass="cucumber.CucumberRunEngine"
}
repositories {
}
Gradle.properties
# versions of dependencies used in this project defined here
groovyVersion=2.5.7
commonCliVersion=1.3.1
commonsIoVersion=2.6
commonLangVersion=2.6
#JUnit
jUnitVersion=4.8
testNGVersion=7.4.0
jUnitPlatformSuiteVersion=1.9.0
#Cucumber
cucumberVersion=7.4.0
cucumberGroovyVersion=6.10.4
ojdbc7Version=12.1.0.2
coreJavaLibVersion=3.5.21.9
Thank you for any help in advance :)
Your project setup is a bit peculiar. There are too many parts that simply don't belong. For example as a result of using compileOnly you're not including the code you need at runtime. And so Cucumber complains it can't find cucumber-java (a backend).
Now you may have already noticed this and scoped cucumber-core to implementation for this reason. But this suggests you're fixing one error at a time rather then building a fundamental understanding of the tools you use.
So it's worth reading how Gradle does dependency management for you:
https://docs.gradle.org/5.3.1/userguide/java_plugin.html#sec:java_plugin_and_dependency_management
A minimal example can be found in the skeleton project. It is not tailored to your needs, but it should be a good starting point.
https://github.com/cucumber/cucumber-java-skeleton
plugins {
java
}
dependencies {
testImplementation(platform("org.junit:junit-bom:5.9.0"))
testImplementation(platform("io.cucumber:cucumber-bom:7.6.0"))
testImplementation("io.cucumber:cucumber-java")
testImplementation("io.cucumber:cucumber-junit-platform-engine")
testImplementation("org.junit.platform:junit-platform-suite")
testImplementation("org.junit.jupiter:junit-jupiter")
}
repositories {
mavenLocal()
mavenCentral()
}
tasks.withType<Test> {
useJUnitPlatform()
// Work around. Gradle does not include enough information to disambiguate
// between different examples and scenarios.
systemProperty("cucumber.junit-platform.naming-strategy", "long")
}

Querydsl Annotation Processor issue after upgrade to Gradle 5

I have a gradle script which generates querydsl classes from Mongo annotated entities. It was working so far, but after upgrade to Gradle 5 I have a problem with:
* What went wrong:
Execution failed for task ':myproject-common:compileQuerydsl'.
Annotation processor 'org.springframework.data.mongodb.repository.support.MongoAnnotationProcessor' not found
Please find my gradle.build script below. Any ideas what could be wrong? I read that there was change in Gradle 5 that annotation processors are not used by default during compilation and annotationProcessor declaration should be added but when I add it to dependencies the same error occurs.
plugins {
id 'org.springframework.boot' version '2.0.4.RELEASE'
id "com.ewerk.gradle.plugins.querydsl" version "1.0.10"
}
repositories {
mavenCentral()
}
apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'
jar {
enabled = true
baseName = 'myproject-common'
version = '0.0.1-SNAPSHOT'
}
// do no package commons into fat jar
bootJar {
enabled = false
}
querydsl {
library = 'com.querydsl:querydsl-apt:4.1.4'
querydslSourcesDir = 'src/main/querydsl'
springDataMongo = true
}
sourceCompatibility = 11.0
targetCompatibility = 11.0
sourceSets {
main {
java {
srcDirs = ['src/main/java', 'src/main/querydsl']
}
}
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.data:spring-data-mongodb")
compile("org.springframework.boot:spring-boot-starter-data-rest")
compile("org.springframework.boot:spring-boot-starter-security")
compile("com.fasterxml.jackson.datatype:jackson-datatype- jsr310:2.8.6")
compile("com.google.guava:guava:23.0")
compile("commons-io:commons-io:2.5")
compile("org.aspectj:aspectjweaver:1.8.9")
compile("org.apache.commons:commons-lang3:3.5")
compile("commons-collections:commons-collections:3.2.2")
compile("org.javamoney:moneta:1.1")
compile("com.fizzed:rocker-runtime:1.2.0")
compile("com.querydsl:querydsl-core:4.1.4")
compile("com.querydsl:querydsl-mongodb:4.1.4")
compile("com.querydsl:querydsl-apt:4.1.4")
compile("com.codepoetics:protonpack:1.15")
testCompile("org.springframework.boot:spring-boot-starter-test")
testCompile("org.assertj:assertj-core:3.7.0")
}
This is my working configuration for JPA without using additional plugins. Gradle 5.3, openjdk 11.0.2.
plugins {
id 'java-library'
}
ext {
springBootVersion = '2.2.0.M1'
queryDslVersion = '4.2.1'
}
dependencies {
api(
"com.querydsl:querydsl-jpa:$queryDslVersion"
)
implementation(
platform("org.springframework.boot:spring-boot-dependencies:$springBootVersion"),
'org.springframework.boot:spring-boot-starter-validation',
'org.springframework.boot:spring-boot-starter-data-jpa',
'org.liquibase:liquibase-core',
'org.postgresql:postgresql'
)
annotationProcessor(
platform("org.springframework.boot:spring-boot-dependencies:$springBootVersion"),
'jakarta.persistence:jakarta.persistence-api',
'jakarta.annotation:jakarta.annotation-api',
"com.querydsl:querydsl-apt:$queryDslVersion:jpa"
)
}
Please pay attention to the annotation processor. It has suffix ":jpa". Probably this is what you missed. To activate the same one for mongodb you should add ":morphia" suffix.
Please also look at these 2 dependencies:
'jakarta.persistence:jakarta.persistence-api'
'jakarta.annotation:jakarta.annotation-api'
This is a workaround for the issue described here:
https://discuss.gradle.org/t/annotationprocessor-querydsl-java-lang-noclassdeffounderror/27107
They should be transitive dependencies of the annotation processor, but they aren't yet. Probably you will have to include some mongo dependencies to annotationProcessor too.
Generated sources are located in \build\generated\sources\annotationProcessor\java\main
I have finally found a workaround. Querydsl's lack of compatibility with Gradle 5 is reported here as a bug: https://github.com/ewerk/gradle-plugins/issues/108
Workaround is to add to gradle script:
compileQuerydsl {
options.annotationProcessorPath = configurations.querydsl
}
I could solve the problem by adding the following two dependencies.
annotationProcessor "com.querydsl:querydsl-apt:4.2.1:jpa"
annotationProcessor 'javax.annotation:javax.annotation-api:1.3.1'
The second dependency was a hidden reason why it not worked for me.
I faced the same issue for Spring Boot Data JPA and Query DSL with Gradle 6.6.1. I tried so many things in my build.gradle file, including some of the suggestions in other responses to this question. I was able to come up with a build.gradle file with a minimal set of additions to the standard build file (standard in the sense of the one generated by https://start.spring.io). Here it is:
plugins {
id 'org.springframework.boot' version '2.4.0'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
id 'com.ewerk.gradle.plugins.querydsl' version "1.0.10"
}
group = 'org.code'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
querydsl {
querydslDefault = true
jpa = true
}
configurations {
querydsl.extendsFrom implementation
}
compileQuerydsl {
options.annotationProcessorPath = configurations.querydsl
}
ext {
queryDslVersion = '4.4.0'
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation "com.querydsl:querydsl-jpa:${queryDslVersion}"
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}
The key addition is the Query DSL plugin:
id 'com.ewerk.gradle.plugins.querydsl' version "1.0.10"
However, it is not enough on its own. Other important additions are:
querydsl {
querydslDefault = true
jpa = true
}
configurations {
querydsl.extendsFrom implementation
}
compileQuerydsl {
options.annotationProcessorPath = configurations.querydsl
}
The configuration i am using,it works:
plugins {
id 'org.springframework.boot' version '2.2.5.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
id "com.ewerk.gradle.plugins.querydsl" version "1.0.10"
}
group = 'io.loremipsum'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
querydsl {
library = 'com.querydsl:querydsl-apt:4.1.4'
querydslSourcesDir = 'src/main/querydsl'
springDataMongo = true
}
sourceSets {
main {
java {
srcDirs = ['src/main/java', 'src/main/querydsl']
}
}
}
// is required when gradle > 5.0
compileQuerydsl {
options.annotationProcessorPath = configurations.querydsl
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-data-mongodb'
compile 'org.springframework.boot:spring-boot-starter-web'
compile("com.querydsl:querydsl-core:4.1.4")
compile("com.querydsl:querydsl-mongodb:4.1.4")
compile("com.querydsl:querydsl-apt:4.1.4")
compile 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile 'de.flapdoodle.embed:de.flapdoodle.embed.mongo'
}
pay attention to the dependency declaration:
compile 'org.springframework.boot:spring-boot-starter-data-mongodb'
implementation dependency should not be used or will result in an exception:
Annotation processor 'org.springframework.data.mongodb.repository.support.MongoAnnotationProcessor' not found
I see you have compile("com.querydsl:querydsl-apt:4.1.4") in your dependencies. According to the docs
Since implementation details matter for annotation processors, they must be declared separately on the annotation processor path. Gradle ignores annotation processors on the compile classpath.
So, put com.querydsl:querydsl-apt:4.1.4 in the annotationProcessor scope.
BTW, consider switching to api / implementation scopes over compile.

Gradle multiple subproject with different spring boot plugin

I have multi project build structure and spring boot is applied from the parent to all subprojects. Here's the parent build.gradle
buildscript {
repositories {
maven {
url 'http://someurl.com/repository/MavenRepositoryGroup/'
}
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:1.5.8.RELEASE"
}
}
subprojects {
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'
apply plugin: 'war'
apply plugin: 'org.springframework.boot'
..
..
..
}
}
Among multiple subprojects, I have a requirement to upgrade just one subproject to spring boot 2 version. How to do it?
It's pretty easy, just declare plugins in subprojects directly, where they are used. BTW, consider using new plugins DSL instead of apply. Take a look at a demo project I created for you. Here are the most interesting parts:
settings.gradle:
rootProject.name = "so53381565"
enableFeaturePreview("IMPROVED_POM_SUPPORT")
include(":a")
include(":b")
include(":c")
build.gradle:
subprojects {
apply plugin: "java"
repositories {
jcenter()
}
}
wrapper {
gradleVersion = "4.10.2"
distributionType = Wrapper.DistributionType.ALL
}
a/build.gradle:
plugins {
id "org.springframework.boot" version "1.5.8.RELEASE"
}
dependencies {
implementation "org.springframework.boot:spring-boot-starter"
}
b/build.gradle:
plugins {
id "org.springframework.boot" version "1.5.17.RELEASE"
}
dependencies {
implementation "org.springframework.boot:spring-boot-starter"
}
c/build.gradle:
plugins {
id "org.springframework.boot" version "2.0.6.RELEASE"
}
dependencies {
implementation "org.springframework.boot:spring-boot-dependencies:2.0.6.RELEASE"
implementation "org.springframework.boot:spring-boot-starter"
}
App.java:
#SpringBootApplication
public class App implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
#Override
public void run(String... args) throws Exception {
System.out.println(SpringVersion.getVersion());
}
}
App.java is the same in all three subprojects. Executing ./gradlew clean :a:bootRun :b:bootRun :c:bootRun will output something like:
…
4.3.12.RELEASE
…
4.3.20.RELEASE
…
5.0.10.RELEASE
…
As you see, you're using three different Springs in three different subprojects.
EDIT
First of all, you can still use apply, just put them in subprojects.
Second, you can use plugins with your own repositories and dependencies, even with those not published in Gradle's Plugin Repository by adding a pluginManagement block in settings.gradle (this is Kotlin DSL from my project):
pluginManagement {
repositories {
gradlePluginPortal()
add(jcenter())
add(maven("http://my.jfrog.io"))
}
resolutionStrategy {
eachPlugin {
if (requested.id.id == "by.dev.madhead.some-plugin") {
useModule("by.dev.madhead:some-gradle-plugin:${requested.version}")
}
}
}
}
Now I am able to use by.dev.madhead.some-plugin in plugins DSL across the project:
plugins {
id("by.dev.madhead.some-plugin").version("42")
}
And it will be substituted by by.dev.madhead:some-gradle-plugin:42

using springboot with local elastic-search instance not working

I want to use elasticSearch repository inside a spring boot application .
I have a local running instance of elastic search 5.5.2
I've search for a while, tried so many combinations of the several sources but nothing yield a working solution , and right now I'm stuck with error :
Error creating bean with name 'elasticsearchTemplate'
what am i doing wrong ?
This is my main class
#SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
public class Application {
public static void main(String[] args) {
Logger logger = LoggerFactory.getLogger("chapters.introduction.HelloWorld1");
try
{
SpringApplication.run(Application.class, args);
}
catch(Exception e)
{
logger.info("caught an exception",e);
}
}
}
config class
#Configuration
#EnableElasticsearchRepositories(basePackages = "hello")
#ComponentScan(basePackages = {"hello"})
public class config {
#Bean
public NodeBuilder nodeBuilder() {
return new NodeBuilder();
}
#Bean
public ElasticsearchOperations elasticsearchTemplate() {
Settings.Builder elasticsearchSettings =
Settings.settingsBuilder()
.put("http.enabled", "false") // 1
.put("path.data", "/home/nad/elasticsearch_data") // 2
.put("path.home", "/home/nad/Downloads/elasticsearch-5.5.2"); // 3
return new ElasticsearchTemplate(nodeBuilder()
.local(true)
.settings(elasticsearchSettings.build())
.node()
.client());
}
}
my build.gradle file
group 'FirstWebServer'
version '1.0-SNAPSHOT'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.8.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'gs-spring-boot'
version = '0.1.0'
}
repositories {
maven { url "http://repo.spring.io/milestone" }
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
// tag::jetty[]
compile("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
}
compile("org.springframework.boot:spring-boot-starter-jetty")
// end::jetty[]
// tag::actuator[]
compile("org.springframework.boot:spring-boot-starter-actuator")
// end::actuator[]
//compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-elasticsearch', version: '1.2.5.RELEASE'
compile group: 'org.springframework.data', name: 'spring-data-elasticsearch', version: '3.0.1.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-parent', version: '2.0.0.M6', ext: 'pom'
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile group: 'org.projectlombok', name: 'lombok', version: '1.16.18'
testCompile("junit:junit")
}
what is the proper way of configuration ? some examples shows application.properties configuration , some dont .
What about compatability , some shows that only elasticsearch 2. * or lower, some said that 5
Its really confusing :(
Thank you very much for your help
To use Elasticsearch 5.x you need Spring Data release Kay (already released), which is only part of Spring Boot 2 (to be released soon). Right now your only option really is to use the latest Spring Boot 2 build and wait for a stable release.
Some people tried using Spring Data Kay with Spring boot 1.5, but ended up in dependency hell. Probably not worth the pain with Spring Boot 2 just around the corner.

spring web developement - disable caching for static content

I'm developping a angularjs application with Spring.
I often have to change my html/javascript file and I noticed that spring is caching static contents. How can I disable that?
I already tried this ...
#Configuration
#AutoConfigureAfter(DispatcherServletAutoConfiguration.class)
class WebMvcConfig extends WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter {
#Autowired
private Environment env;
#Bean
public ResourceUrlEncodingFilter resourceUrlEncodingFilter() {
return new ResourceUrlEncodingFilter();
}
#Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
boolean devMode = this.env.acceptsProfiles("dev");
//boolean useResourceCache = !devMode;
boolean useResourceCache = false;
Integer cachePeriod = devMode ? 0 : null;
registry.addResourceHandler("/public/**")
.addResourceLocations("/public/", "classpath:/public/")
.setCachePeriod(cachePeriod)
.resourceChain(useResourceCache)
.addResolver(new GzipResourceResolver())
.addResolver(new VersionResourceResolver().addContentVersionStrategy("/**"))
.addTransformer(new AppCacheManifestTransformer());
}
}
and that ...
WebContentInterceptor webContentInterceptor;
public #Bean WebContentInterceptor webContentInterceptor () {
if (this.webContentInterceptor == null) {
this.webContentInterceptor = new WebContentInterceptor();
this.webContentInterceptor.setAlwaysUseFullPath (true);
this.webContentInterceptor.setCacheSeconds (0);
this.webContentInterceptor.setCacheMappings (new Properties() {
private static final long serialVersionUID = 1L;
{
put ("/styles/**", "0");
put ("/scripts/**", "0");
put ("/images/**", "0");
put ("/js/**", "0");
}
});
}
return this.webContentInterceptor;
}
this is my build.gradle file
group 'xyz'
version '1.0-SNAPSHOT'
buildscript{
repositories{
mavenCentral()
}
dependencies{
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.2.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://repository.jboss.org/nexus/content/repositories/releases" }
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.security:spring-security-web:4.0.3.RELEASE'
compile 'net.sf.dozer:dozer:5.4.0'
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
compile 'com.h2database:h2'// For Testing purpose
compile 'com.google.guava:guava:19.0' // google library for data collections
testCompile("junit:junit")
//testCompile group: 'junit', name: 'junit', version: '4.11'
}
task wrapper(type: Wrapper){
gradleVersion = '2.3'
}
configurations.all {
// https://stackoverflow.com/questions/14024756/slf4j-class-path-contains-multiple-slf4j-bindings/25694764#25694764
exclude module: 'slf4j-log4j12'
}
Just put this configuration option into your application.properties:
spring.resources.chain.cache=false # Disable caching in the Resource chain.
You may want to also take a look at more fine grained config options related to Static content served by Spring Boot (scroll down to section # SPRING RESOURCES HANDLING).
Additionally, there may be static resources cached by infrastructure that is not handled by Spring Boot and it's container (e.g Web Browser). If you want to overcome this type of caching, there is option to use technique called cache busting. Read this section of Spring Boot docs to get more info about it.
It was a silly mistake. I was editing the HTML/CSS/JS source files but the compiled and deployed version was not affected from this modification.
To see not compiled but the very version of static content you're editing set in application.yml something like:
spring:
profiles: dev
resources:
static-locations: file:src/main/resources/static
But do so only in dev profile to avoid problem after deployment.
Add this is in application.properties
Use this if you want to cache for a particular amount of time
spring.resources.cache.cachecontrol.cache-public=true spring.resources.cache.cachecontrol.max-age=2000 #(2 seconds)
Use this if you don't want any cache
spring.resources.cache.cachecontrol.no-cache=true
But try to adopt first way, as it is not a good practice to load static content every time from server

Categories