1. 新建一个项目
2. 修改 build.gradle
buildscript {
ext.cubaVersion = '7.2.13'
ext.scalaVersion = '2.13.6'
repositories {
maven {
url 'https://nexus.cuba-platform.cn/repository/cuba/'
}
maven {
url 'https://maven.aliyun.com/repository/public'
}
}
dependencies {
classpath "com.haulmont.gradle:cuba-plugin:$cubaVersion"
}
}
def modulePrefix = 'app'
def globalModule = project(":${modulePrefix}-global")
def coreModule = project(":${modulePrefix}-core")
def webModule = project(":${modulePrefix}-web")
def servletApi = 'javax.servlet:javax.servlet-api:3.1.0'
apply(plugin: 'cuba')
apply(plugin: 'scala')
cuba {
artifact {
group = 'com.trdeep.rtis'
version = '0.1'
isSnapshot = true
}
tomcat {
port = '8081'
}
}
dependencies {
appComponent("com.haulmont.cuba:cuba-global:$cubaVersion")
appComponent('cn.cuba.trans:transcn-global:7.2.0')
appComponent('com.haulmont.addon.helium:helium-global:0.3.1')
appComponent('com.haulmont.addon.restapi:restapi-global:7.2.3')
}
def mysql = 'mysql:mysql-connector-java:8.0.15'
configure([globalModule, coreModule, webModule]) {
apply(plugin: 'java')
apply(plugin: 'maven')
apply(plugin: 'cuba')
apply(plugin: 'scala')
dependencies {
testCompile('org.junit.jupiter:junit-jupiter-api:5.5.2')
testCompile('org.junit.jupiter:junit-jupiter-engine:5.5.2')
testCompile('org.junit.vintage:junit-vintage-engine:5.5.2')
compile("org.scala-lang:scala-library:$scalaVersion")
compile("org.scala-lang:scala-compiler:$scalaVersion")
compile("org.scala-lang:scala-reflect:$scalaVersion")
}
task sourceJar(type: Jar) {
from file('java')
classifier = 'sources'
}
artifacts {
archives sourceJar
}
test {
useJUnitPlatform()
}
}
configure(globalModule) {
dependencies {
if (!JavaVersion.current().isJava8()) {
runtime('javax.xml.bind:jaxb-api:2.3.1')
runtime('org.glassfish.jaxb:jaxb-runtime:2.3.1')
}
}
entitiesEnhancing {
main {
enabled = true
}
}
}
configure(coreModule) {
configurations {
jdbc
dbscripts
}
dependencies {
compile(globalModule)
compileOnly(servletApi)
jdbc(mysql)
testRuntime(mysql)
}
task cleanConf(description: 'Cleans up conf directory', type: Delete) {
delete "$cuba.appHome/${modulePrefix}-core/conf"
}
task deploy(dependsOn: [assemble, cleanConf], type: CubaDeployment) {
appName = "${modulePrefix}-core"
appJars(modulePrefix + '-global', modulePrefix + '-core')
}
task createDb(dependsOn: assembleDbScripts, description: 'Creates local database', type: CubaDbCreation) {
}
task updateDb(dependsOn: assembleDbScripts, description: 'Updates local database', type: CubaDbUpdate) {
}
}
configure(webModule) {
configurations {
webcontent
}
dependencies {
compileOnly(servletApi)
compile(globalModule)
}
task webArchive(type: Zip) {
from file("$buildDir/web")
from file('web')
classifier = 'web'
}
artifacts {
archives webArchive
}
task deployConf(type: Copy) {
from file('src')
include "com/trdeep/rtis/**"
into "$cuba.appHome/${modulePrefix}/conf"
}
task clearMessagesCache(type: CubaClearMessagesCache) {
appName = "${modulePrefix}"
}
deployConf.dependsOn clearMessagesCache
task cleanConf(description: 'Cleans up conf directory', type: Delete) {
delete "$cuba.appHome/${modulePrefix}/conf"
}
task deploy(dependsOn: [assemble, cleanConf], type: CubaDeployment) {
appName = "${modulePrefix}"
appJars(modulePrefix + '-global', modulePrefix + '-web')
}
task buildScssThemes(type: CubaWebScssThemeCreation)
task deployThemes(type: CubaDeployThemeTask, dependsOn: buildScssThemes)
assemble.dependsOn buildScssThemes
task themesJar(type: Jar) {
from file('themes')
classifier = 'themes'
}
artifacts {
archives themesJar
}
}
task undeploy(type: Delete, dependsOn: ":${modulePrefix}-web:cleanConf") {
delete("$cuba.tomcat.dir/shared")
delete("$cuba.tomcat.dir/webapps/${modulePrefix}-core")
delete("$cuba.tomcat.dir/webapps/${modulePrefix}")
}
task restart(dependsOn: ['stop', ":${modulePrefix}-core:deploy", ":${modulePrefix}-web:deploy"], description: 'Redeploys applications and restarts local Tomcat') {
doLast {
ant.waitfor(maxwait: 6, maxwaitunit: 'second', checkevery: 2, checkeveryunit: 'second') {
not {
socket(server: 'localhost', port: '8787')
}
}
}
}
restart.finalizedBy start
task buildUberJar(type: CubaUberJarBuilding) {
singleJar = true
appProperties = ['cuba.automaticDatabaseUpdate': true]
}
添加处
就不一一列了,从上往下,对着上面的文件看。
ext.scalaVersion = '2.13.6'
apply(plugin: 'scala')
apply(plugin: 'scala')
compile("org.scala-lang:scala-library:$scalaVersion")
compile("org.scala-lang:scala-compiler:$scalaVersion")
compile("org.scala-lang:scala-reflect:$scalaVersion")
build
3. 在每个子模块项目里添加 scala文件夹
4. 写点Scala代码测试一下
在screens里调用一下试试看
打包测试
。。。竟然成功了?