您好,登錄后才能下訂單哦!
這期內(nèi)容當(dāng)中小編將會給大家?guī)碛嘘P(guān)maven中怎么創(chuàng)建一個scala 項目,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
使用maven創(chuàng)建scala項目,scala-archetype-simple有bug,會遇到一些問題,這里整理記錄一下。
我的環(huán)境是:
maven 3.3.9eclipse 4.6java 1.8
mvn archetype:generate -B \ -DarchetypeGroupId=net.alchim31.maven -DarchetypeArtifactId=scala-archetype-simple -DarchetypeVersion=1.6 \ -DgroupId=com.hainiubl.scala -DartifactId=scala-demo -Dversion=1.0 -Dpackage=com.hainiubl.scala.demo
命令執(zhí)行完后的目錄結(jié)構(gòu):
scala-demo tree.├── pom.xml ├── src │ ├── main │ │ └── scala │ │ └── com │ │ └── hainiubl │ │ └── scala │ │ └── demo │ │ └── App.scala │ └── test │ └── scala │ └── samples │ ├── junit.scala │ ├── scalatest.scala │ └── specs.scala └── target
使用scala 2.11 編譯工程會有問題:
scala 2.11不支持這個make參數(shù)了,從pom.xml中把這個參數(shù)去掉
[ERROR] scalac error: bad option: '-make:transitive'
生成的pom.xml缺少一個依賴
[ERROR] /Users/sandy/workspace/scala-demo/src/test/scala/samples/specs.scala:18: error: not found: type JUnitRunner[ERROR] @RunWith(classOf[JUnitRunner])[ERROR] ^[ERROR] one error found
在pom.xml中增加
<dependency> <groupId>org.specs2</groupId> <artifactId>specs2-junit_${scala.compat.version}</artifactId> <version>2.4.16</version> <scope>test</scope> </dependency>
java 和 scala的版本可以修改成你想要的版本
我這里改成了1.8
修改后完整的pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.hainiubl.scala</groupId> <artifactId>scala-demo</artifactId> <version>1.0</version> <name>${project.artifactId}</name> <description>My wonderfull scala app</description> <inceptionYear>2015</inceptionYear> <licenses> <license> <name>My License</name> <url>http://....</url> <distribution>repo</distribution> </license> </licenses> <properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <encoding>UTF-8</encoding> <scala.version>2.11.8</scala.version> <scala.compat.version>2.11</scala.compat.version> </properties> <dependencies> <dependency> <groupId>org.scala-lang</groupId> <artifactId>scala-library</artifactId> <version>${scala.version}</version> </dependency> <!-- Test --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <dependency> <groupId>org.specs2</groupId> <artifactId>specs2-core_${scala.compat.version}</artifactId> <version>2.4.16</version> <scope>test</scope> </dependency> <dependency> <groupId>org.specs2</groupId> <artifactId>specs2-junit_${scala.compat.version}</artifactId> <version>2.4.16</version> <scope>test</scope> </dependency> <dependency> <groupId>org.scalatest</groupId> <artifactId>scalatest_${scala.compat.version}</artifactId> <version>2.2.4</version> <scope>test</scope> </dependency> </dependencies> <build> <sourceDirectory>src/main/scala</sourceDirectory> <testSourceDirectory>src/test/scala</testSourceDirectory> <plugins> <plugin> <!-- see http://davidb.github.com/scala-maven-plugin --> <groupId>net.alchim31.maven</groupId> <artifactId>scala-maven-plugin</artifactId> <version>3.2.0</version> <executions> <execution> <goals> <goal>compile</goal> <goal>testCompile</goal> </goals> <configuration> <args> <arg>-dependencyfile</arg> <arg>${project.build.directory}/.scala_dependencies</arg> </args> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.18.1</version> <configuration> <useFile>false</useFile> <disableXmlReport>true</disableXmlReport> <!-- If you have classpath issue like NoDefClassError,... --> <!-- useManifestOnlyJar>false</useManifestOnlyJar --> <includes> <include>**/*Test.*</include> <include>**/*Suite.*</include> </includes> </configuration> </plugin> </plugins> </build></project>
打包編譯一下:
mvn package
默認(rèn)沒有scala的archetype,創(chuàng)建maven項目時自己指定一下:
archetype GroupId:net.alchim31.maven
archetype ArtifactId:scala-archetype-simple
archetypeVersion:1.6
1.5或1.6都可以,創(chuàng)建好項目后自己可以修改相應(yīng)版本
scala-archetype-simple源碼
其它修改可以參考上面的 pom.xml,道理是一樣的。
pom.xml 還有可能會報錯:
Multiple annotations found at this line: - Plugin execution not covered by lifecycle configuration: net.alchim31.maven:scala-maven-plugin:3.2.0:testCompile (execution: default, phase: test-compile) - Plugin execution not covered by lifecycle configuration: net.alchim31.maven:scala-maven-plugin:3.2.0:compile (execution: default, phase: compile)
上述就是小編為大家分享的maven中怎么創(chuàng)建一個scala 項目了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。