Gradle scala project on intellij - scala

How do we create a new gradle project with scala ? For a maven scala project we had the help of archtypes. What is the similar technique when I change my build script into gradle so that I can get a readymade project structure to go ahead and add my scala files into the project without adding src folders etc.

You can leverage the build init plugin for this: gradle init --type scala-library
This will create a project in the current directory, setup the Gradle wrapper and generate basic build files.

Related

Gradle other project as dependency in eclipse

I have a web application which depends on another standalone project. Simply the web project requires a standalone project jar to be in classpath. I have built the standalone project jar with gradle and included that in web application's WEB-INF/lib folder. The project is running as expected. Now i want to make it automatic by adding that project as dependency. This is also achieved using the following code.
settings.gralde
include 'job-invoker'
project(':job-invoker').projectDir = new File(settingsDir, '../job-invoker')
build.gradle
dependencies {
compile project(':job-invoker')
.
.
}
I'm able to build the war file from command line using gradle and run it in tomcat. But i'm getting errors in eclipse. I'm not able to run the project in eclipse due to the compilation errors. Can some one please help me. Thanks in advance.
Finally i found a solution for this by installing the other project in maven local repository and adding this as a regular dependency in project. Reference code is given below.
Other project Gradle file
apply plugin: 'maven'
group = 'com.xxx.job'
version = '1.0'
Run gradle install command on this project. Then add mavenLocal() to your repositories in another project and add the dependency
compile 'com.xxx.job:job-invoker:1.0'

How to use gradle and IntelliJ to build a scala project?

Is there a step by step tutorial on how to use gradle to build a scala project in IntelliJ? I tried to research online but couldn't find a complete example.
The default build tool for scala is SBT. This is available in intellij. I highly recommend using it. These are the gradle docs for scala: https://docs.gradle.org/current/userguide/scala_plugin.html
myproject> gradle wrapper --gradle-version 5.0
myproject> ./gradlew init --type scala-library
Init plugin supports type='scala-library' gradle 5.0+. Notice that the second step uses gradle wrapper to initialize the scala project. This is ensure that gradle v5.0 is used irrepective of the version of gradle installed in the respective machine.

View Gradle dependency tree in Eclipse

Is it possible to visualize the dependency tree from inside of Eclipse (e.g. the output of gradle dependencies)? Expanding the Gradle Dependencies tree in Eclipse is a flat view and does not show dependencies for other projects (e.g. if I have a dependency compile project(':project2'), none of project2's dependencies are shown).
Based on this it looks like a tree view is not supported?
Basically I'm looking for the equivalent of this in the maven plugin:
At the time of writing, neither Spring Eclipse Integration Gradle nor Buildship provide a Dependency Hierarchy view we know from m2e.
I don't know when this has been implemented but you can do a gradle dependencies either on command-line or via Buildship Gradle Tasks view within Eclipse. This prints a nice dependency tree of your project's dependencies to the console.
Use gradle 'project-report' plugin to generate report in HTML format.
https://docs.gradle.org/current/userguide/project_report_plugin.html
Add plugin in your build.gradle file:
apply plugin: 'project-report'
And generate report using:
> gradle htmlDependencyReport
For me, it was simply one command
in build.gradle add plugin
apply plugin: 'project-report'
and then go to cmd and run following command
./gradlew htmlDependencyReport
This give me a HTML report WOW Html report 💕
Or if you want the report in a txt file, to make search easy use following command
gradlew dependencyReport
That's all my lord.

sbt eclipse command changed files and packages

I created a new Scala project in eclipse then added a package and Scala object ,
So far so good ...
i want to add external library so i added a project folder with build.properties plugins.sbt files,and another file build.sbt in the root project.
in the terminal i compiled successfully the project with the sbt compile task.
the problem is that after sbt eclipse command the eclipse project changed from Scala project to something else.... all the packages changed to simple folders and the Scala project is ruined
scala IDE :Build id: 3.0.3-20140327-1716-Typesafe
scala version :2.10.4
sbt version:0.13.0
you can see in the image
Where did you get the eclipse command from? I'm guessing you're using sbteclipse.
I created a new Scala project in eclipse then added a package and Scala object , So far so good ...
If I understand correctly, this is exactly the opposite of what the plugin is intended to do. I think you're suppose to create a plain sbt project, and then let the plugin generate the Eclipse project.

Can JetGradle Be Used In IntelliJ 12 Alongside Gradle Generated Project Files That Have Scala Facets?

I've been trying to make the switch to IntelliJ and Gradle for the Java/Scala projects at my company. From the command line Gradle has been great but I've run into a problem when using Gradle with IntelliJ and projects with Scala facets.
I've tried importing projects in both ways and the only one I've been able to get Scala facets working is to run:
gradle idea
using the Gradle IDEA plugin. After that all I need to do it open the ipr file for the project and the projects work fine.
However, there are some Gradle tasks that I would like to run from within IntelliJ for various things (code generation being the biggest one). I would like to be able to use JetGradle to run those tasks. The problem is when I link the Gradle project to JetGradle, the dependencies in each project break the Scala facet's compiler settings.
It's a multi-module project. Here is the build.gradle for the parent:
allprojects {
apply plugin: 'idea'
version = '1.0'
group = 'company-x'
repositories {
mavenCentral()
}
}
And here's the build.gradle for the scala modules:
apply plugin: 'scala'
dependencies {
compile 'org.scala-lang:scala-library:2.10.1',
'org.scala-lang:scala-reflect:2.10.1',
'org.scala-lang:scala-compiler:2.10.1',
'org.slf4j:slf4j-log4j12:1.7.2',
'com.typesafe.akka:akka-actor_2.10:2.1.4'
testCompile 'junit:junit:4.8.1',
'org.scalatest:scalatest:1.2'
}
Before linking the project to JetGradle the Scala facet is setup with a library called 'scala-compiler-2.10.1' that contains the Scala compiler, library, and reflect jars and src. After linking the project, the project libraries are replaced with all of the Gradle project dependencies. The Scala facet then gives the error:
Compiler library: no scala-library*.jar found
When I look at the libraries again, there is still a library called 'scala-compiler-2.10.1' but it's only the compiler. The library and reflect jars are now separated out.
Has anyone out there figured out how to get the Scala facet and JetGradle to play nicely with one another?
From this IntelliJ blog (Better Gradle Support in IntelliJ IDEA 12.1) it seems JetGradle is not ready to support Scala.
I'm waiting for IntelliJ 13.x and stick to Maven for the time being.