β

创建基于maven的java和scala工程

Duff Qiu's Blog 790 阅读

原由


最近在看Scala和ScalaTest,但是要搭建一个同时运行Java和Scala的项目工程,还是遇到了些问题。因为我习惯了搭建出来的工程是Maven工程,同时即要能在Eclipse上运行,也能用Maven命令的方式运行以便后续用Jenkins。经过一段摸索终于试验出来。但是很奇怪,搜索出来的结果没有一个直接好使的。

解决办法


Eclipse配置

<plugin>
			<groupId>org.codehaus.mojo</groupId>
			<artifactId>build-helper-maven-plugin</artifactId>
			<version>1.8</version>
			<executions>
				<execution>
					<id>add-source</id>
					<phase>generate-sources</phase>
					<goals>
						<goal>add-source</goal>
					</goals>
					<configuration>
						<sources>
							<source>src/main/scala</source>
						</sources>
					</configuration>
				</execution>
				<execution>
					<id>add-test-source</id>
					<phase>generate-sources</phase>
					<goals>
						<goal>add-test-source</goal>
					</goals>
					<configuration>
						<sources>
							<source>src/test/scala</source>
						</sources>
					</configuration>
				</execution>
			</executions>
		</plugin>
<plugin>
			<groupId>net.alchim31.maven</groupId>
			<artifactId>scala-maven-plugin</artifactId>
			<version>3.1.6</version>
			<executions>
				<execution>
					<goals>
						<goal>compile</goal>
						<goal>testCompile</goal>
					</goals>
				</execution>
			</executions>
			<configuration>
				<scalaVersion>2.10.3</scalaVersion>
			</configuration>
		</plugin>
<plugin>
			<groupId>org.scalatest</groupId>
			<artifactId>scalatest-maven-plugin</artifactId>
			<version>1.0-RC2</version>
			<configuration>
				<reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
				<junitxml>.</junitxml>
				<filereports>WDF TestSuite.txt</filereports>
			</configuration>
			<executions>
				<execution>
					<id>test</id>
					<goals>
						<goal>test</goal>
					</goals>
				</execution>
			</executions>
		</plugin>
<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-surefire-plugin</artifactId>
			<version>2.17</version>
			<configuration>
				<parallel>methods</parallel>
				<threadCount>10</threadCount>
			</configuration>
		</plugin>

小插曲

不知道什么原因,ScalaTest的官网被屏蔽了。一个纯开源的技术网站有这个必要性么?还是躺枪了?

作者:Duff Qiu's Blog
原文地址:创建基于maven的java和scala工程, 感谢原作者分享。

发表评论