Skip to content

Commit

Permalink
replace gradle apply from cache with cache convention plugin (#24700)
Browse files Browse the repository at this point in the history
* replace gradle apply from cache with cache convention plugin

updates #19615

* drop gradle/cache.gradle.ejs template

---------

Co-authored-by: Marcelo Shima <[email protected]>
  • Loading branch information
atomfrede and mshima authored Dec 30, 2023
1 parent 5b6b5a4 commit 3ffbdab
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 80 deletions.
10 changes: 0 additions & 10 deletions generators/server/templates/gradle.properties.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@ archunitJunit5Version=<%- javaDependencies['archunit-junit5'] %>
<%_ if (enableSwaggerCodegen) { _%>
jacksonDatabindNullableVersion=<%- javaDependencies['jackson-databind-nullable'] %>
<%_ } _%>
<%_ if (cacheProviderCaffeine) { _%>
typesafeConfigVersion=<%- javaDependencies.typesafe %>
<%_ } _%>
<%_ if (cacheProviderHazelcast) { _%>
hazelcastSpringVersion=<%- javaDependencies['hazelcast-spring'] %>
<%_ if (enableHibernateCache) { _%>
hazelcastHibernate53Version=<%- javaDependencies['hazelcast-hibernate53'] %>
<%_ } _%>
<%_ } _%>

<%_ if (databaseTypeSql && reactive) { _%>
commonsBeanutilsVersion=<%- javaDependencies['commons-beanutils'] %>
<%_ } _%>
Expand Down
74 changes: 53 additions & 21 deletions generators/spring-cache/__snapshots__/generator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`generator - spring-cache caffeine-gradle should match files snapshot 1`
".yo-rc.json": {
"stateCleared": "modified",
},
"gradle/cache.gradle": {
"buildSrc/src/main/groovy/jhipster.spring-cache-conventions.gradle": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/config/CacheConfiguration.java": {
Expand All @@ -16,9 +16,21 @@ exports[`generator - spring-cache caffeine-gradle should match files snapshot 1`

exports[`generator - spring-cache caffeine-gradle should match source calls 1`] = `
{
"applyFromGradle": [
"addGradleBuildSrcDependencyCatalogVersion": [
{
"script": "gradle/cache.gradle",
"name": "typesafe",
"version": "'TYPESAFE-VERSION'",
},
],
"addGradleDependencyCatalogVersion": [
{
"name": "typesafe",
"version": "'TYPESAFE-VERSION'",
},
],
"addGradlePlugin": [
{
"id": "jhipster.spring-cache-conventions",
},
],
}
Expand Down Expand Up @@ -89,7 +101,7 @@ exports[`generator - spring-cache ehcache-gradle should match files snapshot 1`]
".yo-rc.json": {
"stateCleared": "modified",
},
"gradle/cache.gradle": {
"buildSrc/src/main/groovy/jhipster.spring-cache-conventions.gradle": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/config/CacheConfiguration.java": {
Expand All @@ -100,9 +112,9 @@ exports[`generator - spring-cache ehcache-gradle should match files snapshot 1`]

exports[`generator - spring-cache ehcache-gradle should match source calls 1`] = `
{
"applyFromGradle": [
"addGradlePlugin": [
{
"script": "gradle/cache.gradle",
"id": "jhipster.spring-cache-conventions",
},
],
}
Expand Down Expand Up @@ -159,7 +171,7 @@ exports[`generator - spring-cache hazelcast-gradle should match files snapshot 1
".yo-rc.json": {
"stateCleared": "modified",
},
"gradle/cache.gradle": {
"buildSrc/src/main/groovy/jhipster.spring-cache-conventions.gradle": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/config/CacheConfiguration.java": {
Expand All @@ -170,9 +182,29 @@ exports[`generator - spring-cache hazelcast-gradle should match files snapshot 1

exports[`generator - spring-cache hazelcast-gradle should match source calls 1`] = `
{
"applyFromGradle": [
"addGradleBuildSrcDependencyCatalogVersion": [
{
"name": "hazelcast-spring",
"version": "'HAZELCAST-SPRING-VERSION'",
},
{
"name": "hazelcast-hibernate53",
"version": "'HAZELCAST-HIBERNATE-53-VERSION'",
},
],
"addGradleDependencyCatalogVersion": [
{
"script": "gradle/cache.gradle",
"name": "hazelcast-spring",
"version": "'HAZELCAST-SPRING-VERSION'",
},
{
"name": "hazelcast-hibernate53",
"version": "'HAZELCAST-HIBERNATE-53-VERSION'",
},
],
"addGradlePlugin": [
{
"id": "jhipster.spring-cache-conventions",
},
],
}
Expand Down Expand Up @@ -241,7 +273,7 @@ exports[`generator - spring-cache infinispan-gradle should match files snapshot
".yo-rc.json": {
"stateCleared": "modified",
},
"gradle/cache.gradle": {
"buildSrc/src/main/groovy/jhipster.spring-cache-conventions.gradle": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/config/CacheConfiguration.java": {
Expand All @@ -255,9 +287,9 @@ exports[`generator - spring-cache infinispan-gradle should match files snapshot

exports[`generator - spring-cache infinispan-gradle should match source calls 1`] = `
{
"applyFromGradle": [
"addGradlePlugin": [
{
"script": "gradle/cache.gradle",
"id": "jhipster.spring-cache-conventions",
},
],
}
Expand Down Expand Up @@ -324,7 +356,7 @@ exports[`generator - spring-cache memcached-gradle should match files snapshot 1
".yo-rc.json": {
"stateCleared": "modified",
},
"gradle/cache.gradle": {
"buildSrc/src/main/groovy/jhipster.spring-cache-conventions.gradle": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/config/CacheConfiguration.java": {
Expand All @@ -335,9 +367,9 @@ exports[`generator - spring-cache memcached-gradle should match files snapshot 1

exports[`generator - spring-cache memcached-gradle should match source calls 1`] = `
{
"applyFromGradle": [
"addGradlePlugin": [
{
"script": "gradle/cache.gradle",
"id": "jhipster.spring-cache-conventions",
},
],
}
Expand Down Expand Up @@ -392,7 +424,7 @@ exports[`generator - spring-cache redis-gradle should match files snapshot 1`] =
".yo-rc.json": {
"stateCleared": "modified",
},
"gradle/cache.gradle": {
"buildSrc/src/main/groovy/jhipster.spring-cache-conventions.gradle": {
"stateCleared": "modified",
},
"src/main/java/com/mycompany/myapp/config/CacheConfiguration.java": {
Expand All @@ -412,15 +444,15 @@ exports[`generator - spring-cache redis-gradle should match files snapshot 1`] =

exports[`generator - spring-cache redis-gradle should match source calls 1`] = `
{
"addTestSpringFactory": [
"addGradlePlugin": [
{
"key": "org.springframework.test.context.ContextCustomizerFactory",
"value": "com.mycompany.myapp.config.RedisTestContainersSpringContextCustomizerFactory",
"id": "jhipster.spring-cache-conventions",
},
],
"applyFromGradle": [
"addTestSpringFactory": [
{
"script": "gradle/cache.gradle",
"key": "org.springframework.test.context.ContextCustomizerFactory",
"value": "com.mycompany.myapp.config.RedisTestContainersSpringContextCustomizerFactory",
},
],
}
Expand Down
5 changes: 5 additions & 0 deletions generators/spring-cache/cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ export default function cleanupTask(this: Generator, { application }: any) {
this.removeFile(`${application.javaPackageTestDir}RedisTestContainerExtension.java`);
}
}
if (application.buildToolGradle) {
if (this.isJhipsterVersionLessThan('8.1.1')) {
this.removeFile('gradle/cache.gradle');
}
}
}
4 changes: 2 additions & 2 deletions generators/spring-cache/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
*/
import Generator from './generator.js';
import { moveToJavaPackageSrcDir, moveToJavaPackageTestDir } from '../java/support/index.js';
import { SERVER_MAIN_SRC_DIR, SERVER_TEST_SRC_DIR } from '../generator-constants.js';
import { SERVER_MAIN_SRC_DIR, SERVER_TEST_SRC_DIR, GRADLE_BUILD_SRC_MAIN_DIR } from '../generator-constants.js';
import { WriteFileSection } from '../base/api.js';

const files: WriteFileSection<Generator, any> = {
cacheFiles: [
{
condition: data => data.buildToolGradle,
templates: ['gradle/cache.gradle'],
templates: [`${GRADLE_BUILD_SRC_MAIN_DIR}/jhipster.spring-cache-conventions.gradle`],
},
{
path: `${SERVER_MAIN_SRC_DIR}_package_/`,
Expand Down
27 changes: 26 additions & 1 deletion generators/spring-cache/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,32 @@ export default class SpringCacheGenerator extends BaseApplicationGenerator {
},
applyGradleScript({ source, application }) {
if (application.buildToolGradle) {
source.applyFromGradle?.({ script: 'gradle/cache.gradle' });
const applicationAny = application as any;
if (applicationAny.cacheProviderCaffeine) {
source.addGradleDependencyCatalogVersion?.({ name: 'typesafe', version: application.javaDependencies?.typesafe });
source.addGradleBuildSrcDependencyCatalogVersion?.({ name: 'typesafe', version: application.javaDependencies?.typesafe });
}
if (applicationAny.cacheProviderHazelcast) {
source.addGradleDependencyCatalogVersion?.({
name: 'hazelcast-spring',
version: application.javaDependencies?.['hazelcast-spring'],
});
source.addGradleBuildSrcDependencyCatalogVersion?.({
name: 'hazelcast-spring',
version: application.javaDependencies?.['hazelcast-spring'],
});
if (applicationAny.enableHibernateCache) {
source.addGradleDependencyCatalogVersion?.({
name: 'hazelcast-hibernate53',
version: application.javaDependencies?.['hazelcast-hibernate53'],
});
source.addGradleBuildSrcDependencyCatalogVersion?.({
name: 'hazelcast-hibernate53',
version: application.javaDependencies?.['hazelcast-hibernate53'],
});
}
}
source.addGradlePlugin?.({ id: 'jhipster.spring-cache-conventions' });
}
},
addDependencies({ application, source }) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
dependencies {
implementation "org.springframework.boot:spring-boot-starter-cache"
<%_ if (cacheProviderEhcache || cacheProviderCaffeine || cacheProviderHazelcast || cacheProviderInfinispan || cacheProviderMemcached) { _%>
implementation "javax.cache:cache-api"
<%_ } _%>
<%_ if (cacheProviderEhcache) { _%>
implementation group: "org.ehcache", name: "ehcache", classifier: "jakarta"
<%_ if (enableHibernateCache) { _%>
implementation "org.hibernate.orm:hibernate-jcache"
<%_ } _%>
<%_ } _%>
<%_ if (cacheProviderCaffeine) { _%>
implementation "com.github.ben-manes.caffeine:caffeine"
implementation "com.github.ben-manes.caffeine:jcache"
implementation "com.typesafe:config:${libs.versions.typesafe.get()}"
<%_ if (enableHibernateCache) { _%>
implementation "org.hibernate.orm:hibernate-jcache"
<%_ } _%>
<%_ } _%>
<%_ if (cacheProviderHazelcast) { _%>
<%_ if (enableHibernateCache) { _%>
implementation "com.hazelcast:hazelcast-hibernate53:${libs.versions.hazelcast.hibernate53.get()}"
<%_ } _%>
implementation "com.hazelcast:hazelcast-spring:${libs.versions.hazelcast.spring.get()}"
<%_ } _%>
<%_ if (cacheProviderInfinispan) { _%>
implementation "org.infinispan:infinispan-hibernate-cache-v62"
implementation "org.infinispan:infinispan-spring-boot3-starter-embedded"
implementation "org.infinispan:infinispan-commons-jakarta"
implementation "org.infinispan:infinispan-core-jakarta"
compileOnly "org.infinispan:infinispan-component-annotations"
<%_ } _%>
<%_ if (cacheProviderMemcached) { _%>
implementation "com.google.code.simple-spring-memcached:spring-cache"
implementation "com.google.code.simple-spring-memcached:xmemcached-provider"
implementation "com.googlecode.xmemcached:xmemcached"
<%_ } _%>
<%_ if (cacheProviderRedis) { _%>
implementation "org.redisson:redisson"
<%_ if (enableHibernateCache) { _%>
implementation "org.hibernate.orm:hibernate-jcache"
<%_ } _%>
testImplementation "org.testcontainers:junit-jupiter"
testImplementation "org.testcontainers:testcontainers"
<%_ } _%>
}

46 changes: 0 additions & 46 deletions generators/spring-cache/templates/gradle/cache.gradle.ejs

This file was deleted.

0 comments on commit 3ffbdab

Please sign in to comment.