首页  

maven 与 sbt 配置对比     所属分类 maven 浏览量 733
maven pom.xml
sbt   build.sbt




maven
<groupId>com.dyyx</groupId>
<artifactId>demo</artifactId>
<version>1.0-SNAPSHOT</version>

sbt
organization := "com.dyyx"
name := "demo"
version := "1.0-SNAPSHOT"


加入源

maven:
<repositories>
        <repository>
            <id>scala-tools.org</id>
            <name>Scala-Tools Maven2 Repository</name>
            <url>http://scala-tools.org/repo-releases</url>
        </repository>
    </repositories>
sbt:
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
resolvers += name at location

加入本地maven库
resolvers += "Local Maven Repository" at "file://"+Path.userHome.absolutePath+"/.m2/repository"


build source
maven:
<sourceDirectory>src/main/scala</sourceDirectory>
        <resources>
            <resource>
                <directory>src/main/resource</directory>
            </resource>
            <resource>
                <directory>src/main/conf</directory>
            </resource>
        </resources>
sbt:
scalaSource in Compile := baseDirectory.value / "src/main/scala"
scalaSource in Test := baseDirectory.value / "src/test"
unmanagedResourceDirectories in Compile += baseDirectory.value / "src/main/resources"

导入依赖包,并排除不须要的包
maven:
<dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-core_2.10</artifactId>
            <version>${spark.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>javax.servlet</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
sbt:
libraryDependencies ++= Seq(
    "org.apache.spark" % "spark-core_2.11" % "1.5.0"  
    )
"log4j" % "log4j" % "1.2.15" excludeAll(
ExclusionRule(organization = "com.sun.jdmk"),
ExclusionRule(organization = "com.sun.jmx"),
ExclusionRule(organization = "javax.jms")

def exclude(org: String, name: String) = excludeAll(ExclusionRule(org, name))


发布 

maven:
<distributionManagement>
        <repository>
            <id>artifactory</id>
            <name>xxxxxx</name>
            <url>http://artifactory.xxxxxx.com/artifactory/xxxxxx/</url>
        </repository>
        <snapshotRepository>
            <id>artifactory</id>
            <name>xxxxxx</name>
            <url>http://artifactory.xxxxxxx.com/artifactory/xxxxxxx/</url>
        </snapshotRepository>
    </distributionManagement>
    
sbt:
publishTo := {
  val nexus = "http://artifactory.xxxxxx.com/artifactory/"
  if (isSnapshot.value)
    Some("snapshots" at nexus + "snapshots")
  else
    Some("releases"  at nexus + "releases")
}
//受权
credentials += Credentials(Path.userHome / ".ivy2" / ".credentials")
其中受权文件为:
realm=Artifactory Realm
host=host
user=userName
password=passWord


测试
maven:
<dependency>
    <groupId>org.scalatest</groupId>
    <artifactId>scalatest_2.11</artifactId>
    <version>3.0.0-M16-SNAP3</version>
    <scope>test</scope>
</dependency>

sbt:
libraryDependencies += "org.scalatest" % "scalatest_2.11" % "3.0.0-M16-SNAP3" % "test"



上一篇     下一篇
使用maven构建scala项目

构建工具sbt 简介

maven 和 sbt 命令对比

获取当前shell脚本所在目录绝对路径

play框架简介

play REST hello 实例