雖然scala的標(biāo)配構(gòu)建工具是sbt,但是隨著kotlin的大火蜜宪,越來越多的人也在使用gradle虫埂。所以就面臨一個(gè)問題,用習(xí)慣gradle的人如何創(chuàng)建scala>項(xiàng)目圃验?
直接google了一番掉伏,很多文章說了半天,就是在講怎么在IDEA里面配置澳窑,更勇的直接手動(dòng)創(chuàng)建文件斧散,感覺是在是太累了。
現(xiàn)在gradle的官網(wǎng)其實(shí)已經(jīng)有如何創(chuàng)建scala項(xiàng)目的指導(dǎo)了
首先在確保已經(jīng)安裝了gradle摊聋。然后創(chuàng)建項(xiàng)目文件夾
mkdir ScalaExample
然后
cd ScalaExample
gradle init --type scala-library
這個(gè)時(shí)候鸡捐,gradle就會(huì)自動(dòng)創(chuàng)建好項(xiàng)目,按提示輸入一些選項(xiàng)麻裁,我這里除了選擇groovy作為gradle模版語言箍镜,其他都是一路Enter。
這個(gè)時(shí)候煎源,build.gradle的內(nèi)容如下:
plugins {
// Apply the scala plugin to add support for Scala
id 'scala'
}
repositories {
// Use jcenter for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
dependencies {
// Use Scala 2.12 in our library project
implementation 'org.scala-lang:scala-library:2.12.7'
// Use Scalatest for testing our library
testImplementation 'junit:junit:4.12'
testImplementation 'org.scalatest:scalatest_2.12:3.0.5'
// Need scala-xml at test runtime
testRuntimeOnly 'org.scala-lang.modules:scala-xml_2.12:1.1.1'
}
由于我目前的scala版本是2.12.8色迂,所以要修改一下對(duì)應(yīng)的版本。
然后配置一下軟件源手销,國內(nèi)推薦是阿里歇僧,因此修改為:
repositories {
// Use jcenter for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
mavenCentral()
jcenter()
}
這樣基本就可以。其他更詳細(xì)的配置就需要參考gradle的文檔原献。