3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

sbtでhosted nexusにjarをuploadして、hosted nexusからjarを取得してsbtで利用する

Last updated at Posted at 2015-07-21

あるあるですが、表題の作業を行ったので備忘録として残します。

1. jarを作成したい側のbuild.sbtの設定

organization := "jp.co.fugafuga.erdrepo.tools"

name := "命名中"

version := "0.0.1-SNAPSHOT"

scalaVersion := "2.11.7"

libraryDependencies ++= Seq(
  "org.scalikejdbc"  %% "scalikejdbc"  % "2.2.+",
  "org.scalikejdbc" %% "scalikejdbc-config"  % "2.2.7",
  "org.slf4j"        %  "slf4j-simple" % "1.7.+",
  "commons-configuration" % "commons-configuration" % "1.10",
  "com.oracle" % "ojdbc6" % "11.1.0.6",
  "org.specs2"       %% "specs2-core"  % "2.4.9" % "test",
  "org.scalikejdbc" % "scalikejdbc-test_2.11" % "2.2.+" % "test",
  "junit"            %  "junit"        % "4.10",
  "net.databinder.dispatch" %% "dispatch-core" % "0.11.0",
  "org.dbunit" % "dbunit" % "2.5.1",
  "org.apache.poi" % "poi" % "3.10-FINAL" % "test"
)

//Nexus用設定
publishTo := {
  val nexus = "http://hosted nexusのアドレス/"
  if (version.value.trim.endsWith("SNAPSHOT"))
    Some("snapshots" at nexus + "content/repositories/hosted-hogehoge-snapshot")
  else
    Some("releases"  at nexus + "content/repositories/hosted-hogehoge")
}

//Nexus用設定
credentials += Credentials("Sonatype Nexus Repository Manager","hosted nexusのアドレス", "ネクサスのユーザ", "ネクサスのパスワード")

//Nexus用設定
resolvers += "Nexus" at "http://hosted nexusのアドレス/content/groups/group-hogehoge"

scalikejdbcSettings

上記のように設定することで、hostedのnexusにorganization, name, versionの情報がmaven風で言うところのgroup, name, versionのようにnexusにjarがuploadされていきます。

uploadについては、sbtのコンソールから以下を実施するのみです

publish

2. sbtプロジェクトでhosted nexusのjarを利用して、jarのmainメソッドを実行する

build.sbtは以下のように用意します。

name := "命名中"

version := "1.0"

scalaVersion := "2.11.7"

libraryDependencies ++= Seq(
  "jp.co.fugafuga.erdrepo.tools" % "命名中_2.11" % "0.0.1-SNAPSHOT",
  "com.oracle" % "ojdbc6" % "11.1.0.6"
)

resolvers += "Nexus" at "http://hosted nexusのアドレス/nexus/content/groups/group-hogehoge"

credentials += Credentials("Sonatype Nexus Repository Manager","hosted nexusのアドレス", "ネクサスのユーザ", "ネクサスのパスワード")

run in Compile <<= Defaults.runTask(fullClasspath in Compile, mainClass in (Compile, run), runner in (Compile, run))

runMain in Compile <<= Defaults.runMainTask(fullClasspath in Compile, runner in (Compile, run))

このような形でbuild.sbtを用意することで、インタラクティブモードで


run "jp.co.fugafuga.erdrepo.tools.命名中.メインメソッドを持つオブジェクト名"

ノン・インタラクティブモードで


sbt "run-main jp.co.fugafuga.erdrepo.tools.命名中.メインメソッドを持つオブジェクト名"

のように実行することが可能になります。

お手軽ですね。

3
3
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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?