Skip to content

Commit

Permalink
Use versions from grails-bom in example apps (#920)
Browse files Browse the repository at this point in the history
* fix(deps): Use versions from `grails-bom` in example apps

And remove unused versions from `gradle.properties`

* build: Remove `webdriver-binaries-gradle-plugin`

As `ContainerGebSpec` is used now, `webdriver-binaries-gradle-plugin` can be removed.

* chore: Remove outdated comment

* chore: Cleanup `examples-grails3-database-per-tenant`

- `AnotherBookService`: Make `save()` method use passed book title
- `Application`: Remove unused imports and old comment
- `application.yml`: Format properly with 2 spaces and group config settings better
- `logback.xml`: Correct faulty pattern
- `build.gradle`: Use correct dependencies and narrow the scopes. Apply Gradle plugins in subproject instead of having logic and conditions in the root build file apply them - much easier to see what's being applied.

* chore: Cleanup `examples-grails3-hibernate5`

- `application.yml`: Format properly with 2 spaces and group config settings better. Remove unused config.
- `logback.xml`: Correct faulty pattern
- `build.gradle`: Use correct dependencies and narrow the scopes. Switch from `tomcat-jdbc` to `HikariCP` as this will be the new default. Apply Gradle plugins in subproject instead of having logic and conditions in the root build file apply them - much easier to see what's being applied.
- `BookControllerUnitSpec`: Remove unused imports and bean definition of deprecated `MimeTypesGrailsPlugin`.
- `UrlMappings`: Move to package so it is pickup up.

* chore: Cleanup `examples-grails3-multiple-datasources`

- `application.yml`: Format properly with 2 spaces and group config settings better. Remove unused config.
- `logback.xml`: Correct faulty pattern
- `Application`: Remove unused imports and old comment
- `build.gradle`: Use correct dependencies and narrow the scopes. Switch from `tomcat-jdbc` to `HikariCP` as this will be the new default. Apply Gradle plugins in subproject instead of having logic and conditions in the root build file apply them - much easier to see what's being applied. Use `astTransformation` configuration for dependencies that needs to be both `compileOnly` and `integrationTestCompileOnly`.

* chore: Cleanup `examples-grails3-partitioned-multi-tenancy`

- `application.yml`: Format properly with 2 spaces and group config settings better. Remove unused config.
- `logback.xml`: Correct faulty pattern
- `AnotherBookService`: Make `save()` method use passed book title
- `PartionedMultiTenancySpec`: Remove unused imports
- `Application`: Remove unused imports and old comment
- `build.gradle`: Use correct dependencies and narrow the scopes. Switch from `tomcat-jdbc` to `HikariCP` as this will be the new default. Apply Gradle plugins in subproject instead of having logic and conditions in the root build file apply them - much easier to see what's being applied.

* chore: Cleanup `examples-grails3-schema-per-tenant`

- `application.yml`: Format properly with 2 spaces and group config settings better. Remove unused config.
- `logback.xml`: Correct faulty pattern
- `AnotherBookService`: Make `save()` method use passed book title
- `SchemaPerTenantSpec`: Remove unused imports
- `Application`: Remove unused imports and old comment
- `build.gradle`: Use correct dependencies and narrow the scopes. Switch from `tomcat-jdbc` to `HikariCP` as this will be the new default. Apply Gradle plugins in subproject instead of having logic and conditions in the root build file apply them - much easier to see what's being applied.

* chore: Cleanup `examples-grails-hibernate-groovy-proxy`

- `application.yml`: Format properly with 2 spaces and group config settings better. Remove unused config.
- `logback.xml`: Correct faulty pattern
- `Customer`: Add no-args constructor needed for proxying
- `ProxySpec`: Remove unused imports
- `Application`: Remove unused imports and old comment
- `build.gradle`: Use correct dependencies and narrow the scopes. Switch from `tomcat-jdbc` to `HikariCP` as this will be the new default. Apply Gradle plugins in subproject instead of having logic and conditions in the root build file apply them - much easier to see what's being applied. Change version variable name from `hibernateGroovyProxy` to `yakworksHibernateGroovyProxyVersion`.

* chore: Cleanup `examples-spring-boot-hibernate5`

- `application.yml`: Format properly with 2 spaces remove unused config.
- `Application`: Exclude `HibernateJpaAutoConfiguration` to avoid duplicate transaction managers: java.lang.ClassCastException: class org.springframework.orm.jpa.EntityManagerHolder cannot be cast to class org.springframework.orm.hibernate5.SessionHolder (org.springframework.orm.jpa.EntityManagerHolder and org.springframework.orm.hibernate5.SessionHolder are in unnamed module of loader 'app')
- `BookController`: Add `@ReadOnly` to `books()` action to get a session for the `Book.list()` method.
- `build.gradle`: Use correct dependencies and narrow the scopes. Switch from `tomcat-jdbc` to `HikariCP` as this will be the new default. Apply Gradle plugins in subproject instead of having logic and conditions in the root build file apply them - much easier to see what's being applied. Add version variable `springBootGradlePluginVersion`.

* test: Extract test for issue 450 from `examples-grails-data-service`

The fix for #450 did not really fit in `examples-grails-data-service`.

This commit adds a new example project, that shows the problem and that it now works (taken from https://github.com/grails-core-issues-forks/multitenantcomposite).

* chore: Cleanup `examples-grails-data-service`

- `MultitenantBook.groovy`: Remove as extracted to examples-issue-450
- `application.yml`: Format properly with 2 spaces and group config settings better. Remove unused config.
- `ClassUsingAService`: Remove dependency on `grails-spring-security-rest`. No need to depend on outside plugins for this test. New test `ServiceInjectionSpec` exercising issue 202.
- `TestService`: Remove unused `transactionService` property
- `logback.xml`: Correct faulty pattern

* chore: Cleanup `examples-standalone-hibernate5`

Use correct dependencies and narrow the scopes. Switch from `tomcat-jdbc` to `HikariCP` as this will be the new default. Apply Gradle plugins in subproject instead of having logic and conditions in the root build file apply them - much easier to see what's being applied.

---------

Co-authored-by: Scott Murphy <[email protected]>
  • Loading branch information
matrei and codeconsole authored Nov 22, 2024
1 parent 56026e5 commit 6f9d931
Show file tree
Hide file tree
Showing 115 changed files with 24,864 additions and 868 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
GRADLE_ENTERPRISE_BUILD_CACHE_NODE_USER: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_USER }}
GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY }}
with:
arguments: build -Dgeb.env=chromeHeadless
arguments: build
publish:
if: github.event_name == 'push'
runs-on: ubuntu-latest
Expand Down
2 changes: 0 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ buildscript {
classpath "org.grails:grails-gradle-plugin:$grailsGradlePluginVersion"
classpath "org.grails.plugins:views-gradle:$viewsGradleVersion"
classpath "org.asciidoctor:asciidoctor-gradle-jvm:$asciidoctorGradleVersion"
classpath "com.github.erdi:webdriver-binaries-gradle-plugin:$webdriverBinariesPluginVersion"
}
}

Expand Down Expand Up @@ -90,7 +89,6 @@ subprojects { Project subproject ->
if (subproject.name != "examples-grails-data-service") {
apply plugin:"org.grails.grails-web"
apply plugin:"org.grails.grails-gsp"
apply plugin:"com.github.erdi.webdriver-binaries"
}
}

Expand Down
50 changes: 24 additions & 26 deletions examples/grails-data-service/build.gradle
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
group "examples"
plugins {
id 'groovy'
id 'org.grails.grails-web'
id 'org.grails.plugins.views-json'
}


apply plugin:"org.grails.grails-web"
apply plugin:"org.grails.plugins.views-json"
apply plugin: 'java'
version = rootProject.version
group = 'examples'

dependencies {
implementation "org.springframework.boot:spring-boot-starter-logging"
implementation "org.springframework.boot:spring-boot-autoconfigure"
implementation "org.grails:grails-core"
implementation "org.springframework.boot:spring-boot-starter-actuator"
implementation "org.springframework.boot:spring-boot-starter-tomcat"
implementation "org.grails:grails-dependencies"
implementation "org.grails:grails-plugin-codecs"
implementation "org.grails:grails-plugin-services"
implementation "org.grails:grails-plugin-datasource"
implementation "org.grails:grails-web-boot"
implementation "org.grails:grails-logging"
implementation "org.grails.plugins:cache"
implementation "org.grails.plugins:events"
implementation project(":grails-plugin")
implementation "org.hibernate:hibernate-core-jakarta:$hibernateVersion"
implementation "org.grails.plugins:views-json"
implementation "org.grails.plugins:views-json-templates"
implementation "org.grails.plugins:spring-security-rest:$grailsSpringSecurityRestVersion"
profile "org.grails.profiles:rest-api"
runtimeOnly "org.apache.tomcat:tomcat-jdbc"
testImplementation "org.grails:grails-gorm-testing-support:$testingSupportVersion"
testImplementation "org.grails:grails-web-testing-support:$testingSupportVersion"

implementation project(':grails-plugin')
implementation 'org.grails:grails-core'
implementation 'org.grails.plugins:views-json'

runtimeOnly 'com.h2database:h2'
runtimeOnly 'com.zaxxer:HikariCP'
runtimeOnly 'org.grails:grails-plugin-databinding'
runtimeOnly 'org.grails:grails-plugin-i18n'
runtimeOnly 'org.grails:grails-plugin-services'
runtimeOnly 'org.grails:grails-plugin-url-mappings'
runtimeOnly 'org.springframework.boot:spring-boot-autoconfigure'
runtimeOnly 'org.springframework.boot:spring-boot-starter-logging'
runtimeOnly 'org.springframework.boot:spring-boot-starter-tomcat'

integrationTestImplementation 'org.grails:grails-testing-support'
}
14 changes: 0 additions & 14 deletions examples/grails-data-service/grails-app/conf/application.groovy

This file was deleted.

171 changes: 58 additions & 113 deletions examples/grails-data-service/grails-app/conf/application.yml
Original file line number Diff line number Diff line change
@@ -1,121 +1,66 @@
grails:
gorm:
multiTenancy:
mode: DISCRIMINATOR
tenantResolverClass: org.grails.datastore.mapping.multitenancy.web.SessionTenantResolver
---
grails:
profile: rest-api
codegen:
defaultPackage: example
gorm:
reactor:
# Whether to translate GORM events into Reactor events
# Disabled by default for performance reasons
events: false
info:
app:
name: '@info.app.name@'
version: '@info.app.version@'
grailsVersion: '@info.app.grailsVersion@'
spring:
jmx:
unique-names: true
main:
banner-mode: "off"
groovy:
template:
check-template-location: false
devtools:
restart:
additional-exclude:
- '*.gsp'
- '**/*.gsp'
- '*.gson'
- '**/*.gson'
- 'logback.groovy'
- '*.properties'
management:
endpoints:
enabled-by-default: false

app:
name: '@info.app.name@'
version: '@info.app.version@'
grailsVersion: '@info.app.grailsVersion@'
---
grails:
mime:
disable:
accept:
header:
userAgents:
- Gecko
- WebKit
- Presto
- Trident
types:
json:
- application/json
- text/json
hal:
- application/hal+json
- application/hal+xml
xml:
- text/xml
- application/xml
atom: application/atom+xml
css: text/css
csv: text/csv
js: text/javascript
rss: application/rss+xml
text: text/plain
all: '*/*'
urlmapping:
cache:
maxsize: 1000
controllers:
defaultScope: singleton
converters:
encoding: UTF-8

profile: rest-api
codegen:
defaultPackage: example
mime:
disable:
accept:
header:
userAgents:
- Gecko
- WebKit
- Presto
- Trident
types:
json:
- application/json
- text/json
hal:
- application/hal+json
- application/hal+xml
xml:
- text/xml
- application/xml
atom: application/atom+xml
css: text/css
csv: text/csv
js: text/javascript
rss: application/rss+xml
text: text/plain
all: '*/*'
urlmapping:
cache:
maxsize: 1000
converters:
encoding: UTF-8
---
hibernate:
cache:
queries: false
use_second_level_cache: false
use_query_cache: false
cache:
queries: false
use_second_level_cache: false
use_query_cache: false
dataSource:
pooled: true
jmxExport: true
driverClassName: org.h2.Driver
username: sa
password: ''
pooled: true
driverClassName: org.h2.Driver
username: sa
password: ''

environments:
development:
dataSource:
dbCreate: create-drop
url: jdbc:h2:mem:devDb;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
test:
dataSource:
dbCreate: update
url: jdbc:h2:mem:testDb;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
production:
dataSource:
dbCreate: none
url: jdbc:h2:./prodDb;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
properties:
jmxEnabled: true
initialSize: 5
maxActive: 50
minIdle: 5
maxIdle: 25
maxWait: 10000
maxAge: 600000
timeBetweenEvictionRunsMillis: 5000
minEvictableIdleTimeMillis: 60000
validationQuery: SELECT 1
validationQueryTimeout: 3
validationInterval: 15000
testOnBorrow: true
testWhileIdle: true
testOnReturn: false
jdbcInterceptors: ConnectionState
defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED
development:
dataSource:
dbCreate: create-drop
url: jdbc:h2:mem:devDb;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
test:
dataSource:
dbCreate: update
url: jdbc:h2:mem:testDb;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
production:
dataSource:
dbCreate: none
url: jdbc:h2:./prodDb;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
2 changes: 1 addition & 1 deletion examples/grails-data-service/grails-app/conf/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<charset>UTF-8</charset>
<pattern>'%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wex'</pattern>
<pattern>%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wex</pattern>
</encoder>
</appender>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import example.LoginAuthenticationSucessHandler
import example.ClassUsingAService
import example.TestBean

// Place your Spring DSL code here
beans = {

restAuthenticationSuccessHandler(LoginAuthenticationSucessHandler) {
classUsingAService(ClassUsingAService) {
testService = ref('testService')
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package example

import grails.gorm.transactions.TransactionService

class TestService {

LibraryService libraryService
TransactionService transactionService

Boolean testDataService(Serializable id) {
libraryService.bookExists(id)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package example

import grails.testing.mixin.integration.Integration
import spock.lang.Issue
import spock.lang.Specification

@Integration
class ServiceInjectionSpec extends Specification {

ClassUsingAService classUsingAService

@Issue('https://github.com/grails/gorm-hibernate5/issues/202')
void 'data-service is injected correctly'() {
when:
classUsingAService.doSomethingWithTheService()

then:
noExceptionThrown()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ class TestServiceSpec extends Specification {

TestService testService
TestBean testBean
ClassUsingAService classUsingAService

@Autowired
List<BookService> bookServiceList

void "test data-service is loaded correctly"() {
when:
classUsingAService.doSomethingWithTheService()

and:
testService.testDataService()

then:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package example

import groovy.transform.CompileStatic

@CompileStatic
class ClassUsingAService {

TestService testService

void doSomethingWithTheService() {
testService.testDataService(1l)
}

}
Loading

0 comments on commit 6f9d931

Please sign in to comment.