Open cjuexuan opened 8 years ago
mvn dependency:tree
maven利用pom.xml进行项目管理
<groupId>com.ximalaya</groupId> <artifactId>testsbtpublish</artifactId> <version>1.0-SNAPSHOT</version>
organization := "com.ximalaya" name := "testsbtpublish" version := "1.0-SNAPSHOT"
<repositories> <repository> <id>scala-tools.org</id> <name>Scala-Tools Maven2 Repository</name> <url>http://scala-tools.org/repo-releases</url> </repository> </repositories>
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"
或者简写为:
resolvers += Resolver.mavenLocal
<sourceDirectory>src/main/scala</sourceDirectory> <resources> <resource> <directory>src/main/resource</directory> </resource> <resource> <directory>src/main/conf</directory> </resource> </resources>
scalaSource in Compile := baseDirectory.value / "src/main/scala" scalaSource in Test := baseDirectory.value / "src/test" unmanagedResourceDirectories in Compile += baseDirectory.value / "src/main/resources"
<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>
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))
<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>
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
<dependency> <groupId>org.scalatest</groupId> <artifactId>scalatest_2.11</artifactId> <version>3.0.0-M16-SNAP3</version> <scope>test</scope> </dependency>
libraryDependencies += "org.scalatest" % "scalatest_2.11" % "3.0.0-M16-SNAP3" % "test"
全局plugins:~/.sbt/0.13/plugins/plugin.sbt 树形:addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.8.2")
~/.sbt/0.13/plugins/plugin.sbt
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.8.2")
sbt vs maven
mvn dependency:tree
ps:最新版的不需要plugin ,运行sbt test:compile即可,会出现在target/resolution-cache/reports下各种非常详细的报告sbt与maven常见命令对比
sbt与maven配置文件对比:
maven利用pom.xml进行项目管理
配置版本,组织:
加入额外的源:
格式为:
如果需要加入本地的maven库:
或者简写为:
build source
导入依赖包,并排除不需要的jar包
其中:
发布:
其中授权文件为:
测试:
sbt plugins
全局plugins:
~/.sbt/0.13/plugins/plugin.sbt
树形:addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.8.2")