Javaã§ãGradleã®ååãããèãæ¨ä»ã§ãããå人çã«ã¯Gradleãããsbtã®æ¹ããã使ã£ã¦ããããããã¡ãã§ã§ãã¦ãããããã¼ã¨ãããã¨ã§ã
ããã¡ãã£ã¨èå³ããã£ãã®ã§èª¿ã¹ã¦æ¸ãã¦ãã¾ãããã©ã¡ããã¨ããã°ãã¿ã¨ã³ããªã«è¿ãããâ¦ãã¾ããæ £ãã¨ããç¹ãããã®ã§ããã¡ãã§èãããã§ããã©ãã¼ã
ã§ã¯ããã£ã¦ã¿ã¾ãããã
ã¨ãããããæ®éã«build.sbtã¨Javaã½ã¼ã¹ã³ã¼ããä½æãã
build.sbtãä½æãã¾ããå
容ã¯ãã¾ãæ®éã«ãä¾åé¢ä¿ã«ã¯ãã¹ã±ã¼ãã´ã¼ãçã«Commons Lang3ã§ããã¾ãããã
build.sbt
name := "sbt-simple-java-project" version := "0.0.1-SNAPSHOT" organization := "org.littlewings" libraryDependencies ++= Seq( "org.apache.commons" % "commons-lang3" % "3.3.2" )
Javaã½ã¼ã¹ã³ã¼ãã¯ããããªæãã§ç¨æã
src/main/java/App.java
import java.util.Arrays; import java.util.List; import java.util.ArrayList; import org.apache.commons.lang3.StringUtils; public class App { public static void main(String[] args) { System.out.println(join(Arrays.asList("Hello", "World"))); } public static String join(Iterable<String> iterable) { return StringUtils.join(iterable, ", "); } }
ãã®ç¶æ ã§ãæ®éã«ã³ã³ãã¤ã«ãã¦
> compile
å®è¡ã§ãã¾ãã
> run [info] Running App Hello, World
ãã®ã¾ã¾ã§ããæ®éã«ä½¿ãããã§ããï¼
ããã¸ã§ã¯ããããScalaã¸ã®ä¾åé¢ä¿ãåãé¤ã
ä¸è¨ã®ããã«ãæä½éã®è¨å®ã§ãæ®éã«ä½¿ãããã§ãããpackageãã¦ã¿ãã¨JARãã¡ã¤ã«ã®ååã«å¦ãªãã®ããã£ã¤ãã¦ãã¾ãã
> package [info] Updating {file:/xxxxx/sbt-simple-java-project/}sbt-simple-java-project... [info] Resolving org.fusesource.jansi#jansi;1.4 ... [info] Done updating. [info] Compiling 1 Java source to /xxxxx/sbt-simple-java-project/target/scala-2.10/classes... [info] Packaging /xxxxx/sbt-simple-java-project/target/scala-2.10/sbt-simple-java-project_2.10-0.0.1-SNAPSHOT.jar ...
ããã§ããã
sbt-simple-java-project_2.10-0.0.1-SNAPSHOT.jar
ã¤ã¾ããScalaã®ãã¼ã¸ã§ã³ãä»ãã¦ãã¾ãã
ããã«è¨ãã¨ãScalaã¸ã®ä¾åé¢ä¿ã¾ã§ãã£ã¤ãã¦ãã¾ãã
ï¼sbt-dependency-graphï¼https://github.com/jrudolph/sbt-dependency-graphï¼ä½¿ç¨
> dependencyTree [info] Updating {file:/xxxxx/sbt-simple-java-project/}sbt-simple-java-project... [info] Resolving org.fusesource.jansi#jansi;1.4 ... [info] Done updating. [info] org.littlewings:sbt-simple-java-project_2.10:0.0.1-SNAPSHOT [S] [info] +-org.apache.commons:commons-lang3:3.3.2
[S]ãä»ãã¦ããã®ã¯ãScalaã¸ã®ä¾åé¢ä¿ããããã¨ã表ãã¦ãã¾ãã
ã¾ããã§ããããJARãã¡ã¤ã«ããScalaã®ãã¼ã¸ã§ã³ãé¤ãã«ã¯ã以ä¸ãbuild.sbtã«å ãã¾ãã
crossPaths := false
ä¾åé¢ä¿ã«Scalaã追å ãããªãããã«ããã«ã¯ã以ä¸ãå ãã¾ãã
autoScalaLibrary := false
ããã¾ã§ã§ãbuild.sbtã¯ãããªãã¾ãããsbtã³ã³ã½ã¼ã«ãèµ·åãã¦ããå ´åã¯ãreloadãã¦ãã ããã
name := "sbt-simple-java-project" version := "0.0.1-SNAPSHOT" organization := "org.littlewings" autoScalaLibrary := false crossPaths := false libraryDependencies ++= Seq( "org.apache.commons" % "commons-lang3" % "3.3.2" )
Javaã½ã¼ã¹ã³ã¼ãã®ã³ã³ãã¤ã«ãªãã·ã§ã³ãæå®ãã
ç¹ã«ä½ããã¦ãããã¨ãå®è¡ç°å¢ã®Javaã®ãã¼ã¸ã§ã³ã§åãããã§ãããæ示çã«æå®ããå ´åã¯ä»¥ä¸ã®æ§ã«è¨å®ãã¾ãã
javacOptions ++= Seq("-source", "1.8", "-target", "1.8")
JUnitãã¹ãã±ã¼ã¹ãå®è¡ãã
ä½æããã½ã¼ã¹ã³ã¼ãã®ããã¹ããç¨æãããã¨ããã£ã¦ã¿ã¾ããããbuild.sbtã®ä¾åé¢ä¿ãã以ä¸ã®æ§ã«ä¿®æ£ãã¾ãã
libraryDependencies ++= Seq( "org.apache.commons" % "commons-lang3" % "3.3.2", "junit" % "junit" % "4.11" % "test" )
ã§ãreloadã
ãã¹ãã³ã¼ããã以ä¸ã®æ§ã«ç¨æãã¦ã¿ã¾ãã
src/test/java/AppTest.java
import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; import java.util.Arrays; import org.junit.Test; public class AppTest { @Test public void testJoin() { assertThat(App.join(Arrays.asList("Hello", "World")), is("Hello, World")); } }
ã§ã¯ããã¹ãå®è¡ã
> test [info] Updating {file:/xxxxx/sbt-simple-java-project/}sbt-simple-java-project... [info] Resolving org.fusesource.jansi#jansi;1.4 ... [info] Done updating. [info] Compiling 1 Java source to /xxxxx/sbt-simple-java-project/target/classes... [info] Compiling 1 Java source to /xxxxx/sbt-simple-java-project/target/test-classes... [info] Passed: Total 0, Failed 0, Errors 0, Passed 0 [info] No tests to run for test:test
ãã¹ãããªãã¨è¨ããã¾ãã
[info] No tests to run for test:test
sbtã§JUnitã®ãã¹ãã±ã¼ã¹ãå®è¡ããããã«ã¯ãããã¡ãã£ã¨è¨å®ãå¿ è¦ã§ãã
ä¾åé¢ä¿ã«ã以ä¸ã追å ãã¾ãã
libraryDependencies ++= Seq( "org.apache.commons" % "commons-lang3" % "3.3.2", "junit" % "junit" % "4.11" % "test", "com.novocode" % "junit-interface" % "0.11-RC1" % "test" )
追å ããã®ã¯ãããã§ããã
"com.novocode" % "junit-interface" % "0.11-RC1" % "test"
sbtã§JUnitãã¹ãã±ã¼ã¹ãå®è¡ããã«ã¯ãjunit-interfaceãå¿ è¦ã«ãªãã¾ãã
junit-interface
https://github.com/sbt/junit-interface
reloadãã¦ããã¹ãå®è¡ã
> test [info] Updating {file:/xxxxx/sbt-simple-java-project/}sbt-simple-java-project... [info] Resolving org.fusesource.jansi#jansi;1.4 ... [info] Done updating. [info] Compiling 1 Java source to /xxxxx/sbt-simple-java-project/target/classes... [info] Compiling 1 Java source to /xxxxx/sbt-simple-java-project/target/test-classes... [info] Passed: Total 1, Failed 0, Errors 0, Passed 1
ãã¹ããå®è¡ããã¾ããã
ããã¾ã§ã§ãbuild.sbtã®è¨å®ã¯ãããªæãã«ãªã£ã¦ãã¾ãã
name := "sbt-simple-java-project" version := "0.0.1-SNAPSHOT" organization := "org.littlewings" javacOptions ++= Seq("-source", "1.8", "-target", "1.8") autoScalaLibrary := false crossPaths := false libraryDependencies ++= Seq( "org.apache.commons" % "commons-lang3" % "3.3.2", "junit" % "junit" % "4.11" % "test", "com.novocode" % "junit-interface" % "0.11-RC1" % "test" )
ã¾ããããã¾ã使ããã¨ã¯ãªãããããã¾ããããç°¡åã«ä½¿ãåã«ã¯ããããï¼
åèï¼
Beginning SBT - A Simple Java-Only Project with Eclipse
http://blog.jiffle.net/post/32451176640/beginning-sbt-a-simple-java-only-project-with-eclipse
Basic Definition Examples
http://www.scala-sbt.org/release/docs/Examples/Quick-Configuration-Examples.html
çªå¤ç·¨ ãã¹ãã§ã®ã¿Scalaã使ç¨ãã
é常ã¯Javaã§æ¸ãããããã©ããã¹ãã³ã¼ãã®ã¿ã§Scalaã使ç¨ãããå ´åã¯ãä¾åé¢ä¿ã«ä»¥ä¸ãå ãã¾ãã
"org.scala-lang" % "scala-library" % scalaVersion.value % "test"
ãã®æã¯ãScalaã®ãã¼ã¸ã§ã³ãæå®ããæ¹ãããæ°ããã¾ãã
scalaVersion := "2.11.0"
ã¤ã¾ãããããªæãã«ãªãã¾ãã
name := "sbt-simple-java-project" version := "0.0.1-SNAPSHOT" scalaVersion := "2.11.0" organization := "org.littlewings" javacOptions ++= Seq("-source", "1.8", "-target", "1.8") autoScalaLibrary := false crossPaths := false libraryDependencies ++= Seq( "org.apache.commons" % "commons-lang3" % "3.3.2", "junit" % "junit" % "4.11" % "test", "com.novocode" % "junit-interface" % "0.11-RC1" % "test", "org.scala-lang" % "scala-library" % scalaVersion.value % "test" )
åèï¼
Configuring Scala
http://www.scala-sbt.org/0.13.2/docs/Detailed-Topics/Configuring-Scala.html