• 使用maven进行scala项目的构建


    目标:
    1、命令行用maven进行scala项目构建
    2、产生eclipse项目文件

    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"> 	<groupId>com.xxx</groupId> 	<artifactId>xxx</artifactId> 	<version>1.0-SNAPSHOT</version> 	<modelVersion>4.0.0</modelVersion>   	<properties> 		<scala.version>2.8.1</scala.version> 	</properties>   	<build> 		<plugins> 			<plugin> 				<artifactId>maven-eclipse-plugin</artifactId> 				<configuration> 					<downloadSources>true</downloadSources> 					<buildcommands> 						<buildcommand>org.scala-ide.sdt.core.scalabuilder</buildcommand> 					</buildcommands> 					<projectnatures> 						<projectnature>org.scala-ide.sdt.core.scalanature</projectnature> 						<projectnature>org.eclipse.jdt.core.javanature</projectnature> 					</projectnatures> 					<classpathContainers> 						<classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer> 						<classpathContainer>org.scala-ide.sdt.launching.SCALA_CONTAINER</classpathContainer> 					</classpathContainers> 					<sourceIncludes> 						<sourceInclude>**/*.scala</sourceInclude> 					</sourceIncludes> 				</configuration> 			</plugin> 			<plugin> 				<groupId>org.scala-tools</groupId> 				<artifactId>maven-scala-plugin</artifactId> 				<executions> 					<execution> 						<goals> 							<goal>compile</goal> 							<goal>testCompile</goal> 						</goals> 					</execution> 				</executions> 			</plugin> 			<plugin> 				<groupId>org.codehaus.mojo</groupId> 				<artifactId>build-helper-maven-plugin</artifactId> 				<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> 		</plugins> 	</build> </project>

    要点分析

    	<properties> 		<scala.version>2.8.1</scala.version> 	</properties>

    通过properties定义scala的版本
    因为scala的版本是不兼容的,比如说2.8编译的class文件不能跟2.9的类库一起使用
    这个定义同时会影响maven-scala-plugin中使用的scala版本
    当然你也可以在dependencies中通过${scala.version}使用这个版本号

    maven-eclipse-plugin部分是产生eclipse项目,对应使用scala-ide
    打开downloadSources下载类库源代码,可以在eclipse中直接查看
    sourceIncludes段必须加入,不然会出现代码目录中看不到scala文件的情况

    maven-scala-plugin段用于命令行用maven进行构建

    build-helper-maven-plugin段用于引入额外的代码目录
    这个配置同时对命令行构建和eclipse项目生成有效
    我这个是一个mixed Java/Scala项目

  • 相关阅读:
    2019-3-24
    模板
    试试Markdown编辑器
    Codeforces Round #529 (Div. 3) D. Circular Dance
    Codeforces Round #529 (Div. 3) C. Powers Of Two(数学????)
    poj 2566"Bound Found"(尺取法)
    poj 3273"Monthly Expense"(二分搜索+最小化最大值)
    二分搜索
    Codeforces Round #518 (Div. 2) B LCM
    2018.12.21 浪在ACM 集训队第十次测试赛
  • 原文地址:https://www.cnblogs.com/shihao/p/2300225.html
Copyright © 2020-2023  润新知