來架個網站吧
Grails
昨天可以開啟專案之後,新增最主要的工作內容就是把專案連上資料庫
因為 postgresql 官方網站已經有詳細的安裝步驟,在這邊就不贅述。
postgresql 下載網址: https://www.postgresql.org/download/
安裝完成資料庫之後,就可以建立資料庫,指令如下:
sudo -u postgres psql
-- 新增資料庫
CREATE DATABASE ironman_dict_db;
-- 新增資料庫角色
CREATE ROLE dict_dba NOINHERIT;
-- 授予 dict_dba 角色可連線至 ironman_dict_db 資料庫
GRANT CONNECT ON DATABASE ironman_dict_db TO dict_dba;
-- 授予 dict_dba 在 DATABASE 所有權限
GRANT ALL ON DATABASE ironman_dict_db to dict_dba;
-- 新增 dict_ap 使用者
CREATE USER dict_ap WITH PASSWORD 'LF2.net';
-- 把 dict_ap (user role) 加入 dict (group role) 中
GRANT dict_ap TO dict_dba;
確認專案可以正常部屬之後,接下就是針對當前的專案環境修改內容。主要修改下列文件
grailsVersion=5.3.3
grailsGradlePluginVersion=5.3.0
groovyVersion=3.0.11
gorm.version=7.3.3
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.jvmargs=-Dfile.encoding=UTF-8 -Xmx1024M
springBootVersion=2.7.13
hibernateCore=5.6.15.Final
grailsVersion
一致buildscript {
repositories {
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsGradlePluginVersion"
classpath "gradle.plugin.com.github.erdi.webdriver-binaries:webdriver-binaries-gradle-plugin:2.6"
classpath "org.grails.plugins:hibernate5:7.3.0"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:3.4.7"
}
}
version "0.1"
group "ironman.dict"
apply plugin:"eclipse"
apply plugin:"idea"
apply plugin:"war"
apply plugin:"org.grails.grails-web"
apply plugin:"com.github.erdi.webdriver-binaries"
apply plugin:"org.grails.grails-gsp"
apply plugin:"com.bertramlabs.asset-pipeline"
repositories {
mavenCentral()
maven { url "https://repo.grails.org/grails/core" }
}
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}
dependencies {
developmentOnly("org.springframework.boot:spring-boot-devtools")
compileOnly "io.micronaut:micronaut-inject-groovy"
console "org.grails:grails-console"
implementation "org.springframework.boot:spring-boot-starter-logging:${springBootVersion}"
implementation "org.springframework.boot:spring-boot-starter-validation:${springBootVersion}"
implementation "org.springframework.boot:spring-boot-autoconfigure:${springBootVersion}"
implementation "org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}"
implementation "org.springframework.boot:spring-boot-starter-tomcat:${springBootVersion}"
implementation "org.grails:grails-core"
implementation "org.grails:grails-web-boot"
implementation "org.grails:grails-logging"
implementation "org.grails:grails-plugin-rest"
implementation "org.grails:grails-plugin-databinding"
implementation "org.grails:grails-plugin-i18n"
implementation "org.grails:grails-plugin-services"
implementation "org.grails:grails-plugin-url-mappings"
implementation "org.grails:grails-plugin-interceptors"
implementation "org.grails.plugins:cache"
implementation "org.grails.plugins:async"
implementation "org.grails.plugins:scaffolding"
implementation "org.grails.plugins:hibernate5"
implementation "org.hibernate:hibernate-core:${hibernateCore}"
implementation "org.grails.plugins:events"
implementation "org.grails.plugins:gsp"
profile "org.grails.profiles:web"
runtimeOnly "org.glassfish.web:el-impl:2.2.1-b05"
runtimeOnly "org.apache.tomcat:tomcat-jdbc"
runtimeOnly "javax.xml.bind:jaxb-api:2.3.1"
runtimeOnly "com.bertramlabs.plugins:asset-pipeline-grails:3.4.7"
testImplementation "io.micronaut:micronaut-inject-groovy"
testImplementation "org.grails:grails-gorm-testing-support"
testImplementation "org.mockito:mockito-core"
testImplementation "org.grails:grails-web-testing-support"
testImplementation "org.grails.plugins:geb"
testImplementation "org.seleniumhq.selenium:selenium-remote-driver:4.0.0"
testImplementation "org.seleniumhq.selenium:selenium-api:4.0.0"
testImplementation "org.seleniumhq.selenium:selenium-support:4.0.0"
testRuntimeOnly "org.seleniumhq.selenium:selenium-chrome-driver:4.0.0"
testRuntimeOnly "org.seleniumhq.selenium:selenium-firefox-driver:4.0.0"
// https://mvnrepository.com/artifact/org.postgresql/postgresql
implementation group: 'org.postgresql', name: 'postgresql', version: '42.6.0'
//hikaricp
implementation "com.zaxxer:HikariCP:5.0.1"
}
bootRun {
ignoreExitValue true
jvmArgs(
'-Dspring.output.ansi.enabled=always',
'-noverify',
'-XX:TieredStopAtLevel=1',
'-Xmx1024m')
sourceResources sourceSets.main
String springProfilesActive = 'spring.profiles.active'
systemProperty springProfilesActive, System.getProperty(springProfilesActive)
}
tasks.withType(GroovyCompile) {
configure(groovyOptions) {
forkOptions.jvmArgs = ['-Xmx1024m']
}
}
tasks.withType(Test) {
useJUnitPlatform()
}
webdriverBinaries {
if (!System.getenv().containsKey('GITHUB_ACTIONS')) {
chromedriver {
version = '2.45.0'
fallbackTo32Bit = true
}
geckodriver '0.30.0'
}
}
tasks.withType(Test) {
systemProperty "geb.env", System.getProperty('geb.env')
systemProperty "geb.build.reportsDir", reporting.file("geb/integrationTest")
if (!System.getenv().containsKey('GITHUB_ACTIONS')) {
systemProperty 'webdriver.chrome.driver', System.getProperty('webdriver.chrome.driver')
systemProperty 'webdriver.gecko.driver', System.getProperty('webdriver.gecko.driver')
} else {
systemProperty 'webdriver.chrome.driver', "${System.getenv('CHROMEWEBDRIVER')}/chromedriver"
systemProperty 'webdriver.gecko.driver', "${System.getenv('GECKOWEBDRIVER')}/geckodriver"
}
}
assets {
minifyJs = true
minifyCss = true
}
grails 專案所有中的 plugin 都是在這邊設定。另外,初始化的 gradle.properties
文件,預設會有 H2 相關套件記得移除。