LoginSignup
1
0

More than 5 years have passed since last update.

複数バージョンsbt混合のマルチプロジェクト

Posted at

sbt0.13 でビルドされているマルチプロジェクトを sbt1 に上げようとしたとき、一部 sbt0.13 でしか提供されていないlibraryがあって対応に困った。

最終的にsbtが複数バージョン混じった状態に落ち着けたので、その対応メモ

確認に用いたsbtのバージョン

sbt1 => 1.2.7
sbt0.13 => 0.13.17

概要

元の状態は以下の通り。

projectA projectB でそれぞれ common を参照している。commonsbt1 への対応ができるとする。
projectBsbt0.13 のままにする。

.
├── common
├── projectA
└── projectB

対応後のイメージは以下。

.
├── common
├── projectA-sbt1
└── projectB-sbt0.13

対応方法

commoncommon-src , common-sbt1 , common-sbt0_13 の3つのディレクトリに分ける。

  • common-src: ソースコードを格納する
  • common-sbt1: sbt1用のビルド設定を格納する
  • common-sbt0_13: sbt0.13用のビルド設定を格納する
.
├── common-src
│   ├── main
│   └── test
├── common-sbt1
│   ├── project
│   │  ├── build.properties
│   │  └── plugins.sbt
│   └── build.sbt
├── common-sbt0_13
│   ├── project
│   │  ├── build.properties
│   │  └── plugins.sbt
│   └── build.sbt
├── projectA-sbt1
└── projectB-sbt0_13

common-sbt1 , common-sbt0_13 のビルドは、ビルドパスを common-src を向くようにしてやればいい。

Customizing paths

common-sbt1/build.sbt
common-sbt0_13/build.sbt

sourcesInBase := false
scalaSource in Compile := (baseDirectory(_ / "../common-src/main")).value
scalaSource in Test := (baseDirectory(_ / "../common-src/test")).value
resourceDirectory in Compile := (baseDirectory(_ / "../common-src/main/resources")).value
resourceDirectory in Test := (baseDirectory(_ / "../common-src/test/resources")).value

// 以下はそれぞれのsbtに合わせてscalaVersionなどを修正

projectA-sbt1/build.sbt

lazy val projectA = (project in file("."))
  .dependsOn(RootProject(file("../common-sbt1")))

projectB-sbt0_13/build.sbt

lazy val projectB = (project in file("."))
  .dependsOn(RootProject(file("../common-sbt0_13")))

sbt-scalariform などを使っていて、sbt1に上げるタイミングで sbt-scalafmt に変えたいとき、 commonsbt-scalariform の最新バージョン(sbt1, sbt0.13の両方が提供されている)のままにして、sbt1に上げたプロジェクトのみ sbt-scalafmt に変えるのが良さそう。neo-sbt-scalafmt でもいいかも。

common-sbt1にのみ sbt-scalafmt を設定して、common-sbt0_13からフォーマット用のプラグイン設定を取り除いても動作しますが、common-sbt0_13側からフォーマッタが起動しないので微妙そう。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0