來架個網站吧-12.網站開發-2: 設定環境參數-1
#
tags: 來架個網站吧 Grails
#
我是目錄
昨天可以開啟專案之後,新增最主要的工作內容就是把專案連上資料庫
安裝開發資料庫
#
安裝
#
因為 postgresql 官方網站已經有詳細的安裝步驟,在這邊就不贅述。
postgresql 下載網址: https://www.postgresql.org/download/
開資料庫
#
安裝完成資料庫之後,就可以建立資料庫,指令如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
-- 新增資料庫
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;
|
設定專案環境參數
#
確認專案可以正常部署之後,接下就是針對當前的專案環境修改內容。主要修改下列文件
- gradle.properties
- build.gradle
- grails-app/conf/application.yml
gradle.properties
#
1
2
3
4
5
6
7
8
9
|
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
|
build.gradle
#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
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 相關套件記得移除。