Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Apr 18, 2019. It is now read-only.

Depend on Scala modules like a pro

License

NotificationsYou must be signed in to change notification settings

scala/scala-module-dependency-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This repository shows how to use these build tools:

  • sbt
  • Maven

to depend on Scala standard modules such as:

  • scala-xml, containing thescala.xml package
  • scala-parser-combinators, containing thescala.util.parsing package
  • scala-swing, containing thescala.swing package

These modules were split out from the Scala standard library, beginning with Scala 2.11.

Sbt sample

This sample demonstrates how to conditionally depend on all modules. If use only on some of the modules just edit thelibraryDependencies definition accordingly. If you are just looking for a copy&paste snippet for yourbuild.sbt file, here it is:

// add dependencies on standard Scala modules, in a way// supporting cross-version publishing// taken from: http://github.com/scala/scala-module-dependency-samplelibraryDependencies:= {CrossVersion.partialVersion(scalaVersion.value)match {// if Scala 2.12+ is used, use scala-swing 2.xcaseSome((2, scalaMajor))if scalaMajor>=12=>      libraryDependencies.value++Seq("org.scala-lang.modules"%%"scala-xml"%"1.1.1","org.scala-lang.modules"%%"scala-parser-combinators"%"1.1.1","org.scala-lang.modules"%%"scala-swing"%"2.0.3")caseSome((2, scalaMajor))if scalaMajor>=11=>      libraryDependencies.value++Seq("org.scala-lang.modules"%%"scala-xml"%"1.1.1","org.scala-lang.modules"%%"scala-parser-combinators"%"1.1.1","org.scala-lang.modules"%%"scala-swing"%"1.0.2")case _=>// or just libraryDependencies.value if you don't depend on scala-swing      libraryDependencies.value:+"org.scala-lang"%"scala-swing"% scalaVersion.value  }}

Maven sample

The followingpom.xml snippet assumes you define ascala.compat.version property in your pom.xml file for scala-maven-plugin 3.1.6 or later. For example, thescala.compat.version should be set to2.11 for any Scala 2.11.x version.

<!-- taken from: http://github.com/scala/scala-module-dependency-sample--><dependency>  <groupId>org.scala-lang.modules</groupId>  <artifactId>scala-xml_${scala.compat.version}</artifactId>  <version>1.1.1</version></dependency><dependency>  <groupId>org.scala-lang.modules</groupId>  <artifactId>scala-parser-combinators_${scala.compat.version}</artifactId>  <version>1.1.1</version></dependency><dependency>  <groupId>org.scala-lang.modules</groupId>  <artifactId>scala-swing_${scala.compat.version}</artifactId>  <version>2.0.3</version></dependency>

NOTE: Due to anissue in the Scala compiler, a project that uses scala-xml will compile successfully on Scala 2.11 even without an explicit dependency on thescala-xml module. However, it will fail at runtime due to missing dependency. In order to prevent that mistake we offer a workaround. Add-nobootcp Scala compiler option which will make scala-xml invisible to compilation classpath and your code will fail to compile when the dependency onscala-xml is missing. Check sample pom.xml for details.

Scala cross-versioning with Maven

The snippet provided above allows you to declare dependencies on modules shipped against Scala 2.11. If you would like tosupport building your project with both Scala 2.10, 2.11 and 2.12 at the same time you'll need to useMaven profiles. Check thepom.xml file in the sample project for details how to set up Maven profiles for supporting different Scala versions.

About

Depend on Scala modules like a pro

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors9

Languages


[8]ページ先頭

©2009-2025 Movatter.jp