Create Gradle project in IDE from existing Gradle sources
If you already have a Gradle project, you can easily generate Eclipse or IntelliJ project files using available plugins (Eclipse plugin, IntelliJ plugin). I haven't found anything like that for NetBeans but I'm not a NetBeans user.Create Gradle project from scratch
If you do not have Gradle sources and are starting a project from scratch, it's a bit more tiresome, because at this moment neither Eclipse nor IntelliJ support creating Gradle projects. NetBeans has a Gradle plugin, but I haven't tried it out.(Option 1 - any IDE) In that case you can create a Gradle project skeleton by hand and then import it into your IDE using methods above (there seems to be no way to create a skeleton project automatically at this moment).
(Option 2 - just Eclipse) You can create a new Scala project in your IDE and add Gradle nature - but that at the moment only seems to work in Eclipse. Again, I haven't tried that with NetBeans.
Here's how to do it with SpringSource Tool Suite:- Download and install STS if you haven't already.
- Launch STS.
- Install these extensions: Scala, Gradle, Groovy. Maven support is not needed.
- Create a new Scala Project.
- Create source folders: src/main/scala, src/main/resources, src/test/scala, src/test/resources.
- Right click on the project, Configure -> Convert to Gradle project.
- Create a file called build.gradle in the root project directory.
- Paste sample build.gradle content (see below).
- Right click on the build.gradle file and choose Gradle -> Refresh All. Give it a while...
- Right click on the build.gradle file and choose Run As -> Gradle Build. Tick build and hit Run.
- This should build the project and obtain all dependencies.
- Create a Scala object in a package inside src/main/scala. In my case the package is me.m1key.audioliciousmigration and the class name is Launcher. That corresponds to the build.gradle manifest Main-class declaration.
- Paste Launcher.scala content (from below).
- You can now right click on Launcher, choose Run As -> Scala Application and it will run.
- If you now run gradle install rather that gradle build, it will deploy the artifact to your local Maven (.m2) repository. The artifact name is deduced from the project name.
build.gradle
apply plugin: 'scala' apply plugin: 'maven' sourceCompatibility = 1.6 version = '0.0.1-SNAPSHOT' group = 'me.m1key.audiolicious-migration' jar { manifest { attributes 'Implementation-Title': 'Audiolicious Migration', 'Implementation-Version': version, 'Main-class': 'me.m1key.audioliciousmigration.Launcher' } from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } } repositories { mavenCentral() } dependencies { compile group: 'com.google.inject', name: 'guice', version: '3.0' testCompile group: 'org.scala-tools.testing', name: 'specs_2.9.1', version: '1.6.9' testCompile group: 'junit', name: 'junit', version: '4.+' // Libraries needed to run the scala tools scalaTools 'org.scala-lang:scala-compiler:2.9.1' scalaTools 'org.scala-lang:scala-library:2.9.1' // Libraries needed for scala api compile 'org.scala-lang:scala-library:2.9.1' }
Launcher.scala
package me.m1key.audioliciousmigration object Launcher { def main(args: Array[String]): Unit = { println("Hello world!") } }Once it's built, you can run the jar like that from project root:
java -jar build\libs\audiolicious-migration-0.0.1-SNAPSHOT.jar (Windows)
java -jar build/libs/audiolicious-migration-0.0.1-SNAPSHOT.jar (Unix)
Unit Tests
Here's how to write a unit test. You can run it as a JUnit test in your IDE and it runs as a part of gradle build, which I think is quite cool.package me.m1key.audioliciousmigration import org.specs._ import org.specs.runner._ import org.junit.runner.RunWith @RunWith(classOf[JUnitSuiteRunner]) class LauncherSpec extends Specification with JUnit { "2 + 2" should { "equal 4" in { 2 + 2 mustBe 4 } } }gradle install does not run tests!
I'm having lot's of trouble compiling Scala with 1.0 RC Gradle. Which version are you using?
ReplyDeleteGreat Article android based projects
DeleteJava Training in Chennai
Project Center in Chennai
Java Training in Chennai
projects for cse
The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training
Hi Wojtek, thanks for popping in. I'm using Scala 2.9.1 and Gradle 1.0 milestone 9. What problems exactly are you getting?
ReplyDeleteThanks for answering.
ReplyDeleteI'm using this setup:
$ gradle -v
------------------------------------------------------------
Gradle 1.0-rc-1
------------------------------------------------------------
Gradle build time: Wednesday, April 11, 2012 11:13:24 AM UTC
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.8.2 compiled on December 20 2010
Ivy: 2.2.0
JVM: 1.7.0_147-icedtea (Oracle Corporation 21.0-b17)
OS: Linux 3.0.0-12-generic amd64 (Linux Mint)
I'm getting all the time:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileScala'.
> Cannot invoke method withInputStream() on null object
Ok, I found the cause - missing "scalaTools" in dependencies!
ReplyDeleteThanks for these posts, helped me :-)
Working until it's fixed, judging by the time of your replies. :) Cool, I'm glad; thanks!
ReplyDeleteThanks for the marvelous posting! I certainly enjoyed reading it, you’re a great author.I will ensure that I bookmark your blog and may come back from now on. I want to encourage you to continue your great writing, have a nice day! 한국야동
ReplyDeleteAlso feel free to visit may web page check this link 야설
Greetings! Very useful advice within this article! It’s the little changes that will make the biggest changes. Thanks for sharing! 한국야동
ReplyDeleteAlso feel free to visit may web page check this link 야설
I have to thank you for the efforts you’ve put in penning this blog. I am hoping to check out the same high-grade content from you in the future as well 야동
ReplyDeleteAlso feel free to visit may web page check this link 국산야동
Everything is very open with a really clear description of the issues. It was really informative. Your website is very helpful. Thank you for sharing! 국산야동
ReplyDeleteAlso feel free to visit may web page check this link 한국야동
Your post is very interesting to me. Reading was so much fun. I think the reason reading is fun is because it is a post related to that I am interested in. Articles related to 메이저사이트순위 you are the best. I would like you to write a similar post about !
ReplyDeleteLorsque quelqu'un écrit un article, il garde l'idée
ReplyDeleted'un utilisateur dans son esprit que la façon dont l'utilisateur peut le comprendre.
C'est pourquoi cet article est génial. Merci! 안전토토사이트
슬롯커뮤니티
ReplyDeleteThis is such an amazing and informative post. Thank you for sharing this with us. Keep sharing such stuff. 온라인카지노
ReplyDelete