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

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.

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 build an Xtext Eclipse plug-in with Gradle?

I have written a DSL with Xtext 2.12 and my Xtend 2.12 code generator produces Java 8 code from it. I am using Eclipse Oxygen.3a. I started by creating an Xtext project as an Eclipse plug-in and all works fine, but I would like to have everything built by Gradle now.
For that purpose, I have added the Gradle nature to my Xtext project and launched 'gradle init' to generate the build.gradle and settings.gradle files. I have discovered the existence of Xtext Gradle Plugins (Xtext Builder and Xtend Compiler), and used the documentation of these plugins to write the build.gradle script content, but I did not understand everything and, not surprisingly, my builder does not work. Could you help me please to set this builder up correctly?
plugins {
id 'org.xtext.builder' version '2.0.3'
id "org.xtext.xtend" version "2.0.3"
}
apply plugin: 'java'
apply plugin: 'org.xtext.xtend'
apply plugin: 'eclipse'
sourceSets {
main.java.srcDirs = ['src','xtend-gen']
main.xtendOutputDir = 'xtend-gen'
}
repositories {
mavenCentral()
jcenter()
}
dependencies {
compile group: 'org.eclipse.xtend', name: 'org.eclipse.xtend.lib', version: '2.16.0'
compile group: 'org.eclipse.xtext', name: 'org.eclipse.xtext', version: '2.16.0'
compile group: 'org.eclipse.emf', name: 'org.eclipse.emf.codegen.ecore', version: '2.15.0'
compile group: 'org.eclipse.xtext', name: 'org.eclipse.xtext.xtext.generator', version: '2.16.0'
testCompile group: 'org.eclipse.xtext', name: 'org.eclipse.xtext.xbase.testing', version: '2.16.0'
}
xtext {
languages {
mapy {
setup = 'com.mchp.mapy.MapyStandaloneSetup'
generator.outlet.producesJava = true
}
}
sourceSets {
main {
srcDirs 'src','xtend-gen'
output {
dir(xtext.languages.mapy.generator.outlet, 'src-gen')
}
}
}
}
xtend {
}
Where should the sourceSets block be located (inside or outside the
xtext block)?
Is the xtext block content correct?
What should I write into the xtend block? Should it even be declared?
What is the Gradle task to be run to start the MWE2 launcher and
then the code generator?
Following is a snapshot of my Eclipse project organization.
Thanks in advance for your time!
It is also possible to build the Xtext plugins using Eclipse PDE. I created a dedicated Eclipse deployment to keep the size down (minimal then install the PDE, JDT and Xtext projects) which is published to an artifact repository. It's then just a matter of writing Gradle tasks (or a plugin) to pull down the Eclipse, extract it to the build directory, copy in the Xtext Eclipse projects (use the Xtext Gradle plugin to build the DSL before copying) and finally call the Ant PDE task(s) using the Java command and the AntRunner inside the Eclipse. The output should be a basic update site from which you can either install the plugins from locally or publish to the Artifact repository to share.
A good understanding of Eclipse PDE build process is required. I found most of what I needed in the Eclipse help (https://help.eclipse.org/2020-06/index.jsp) under section "Plug-in Development Environment Guide > Tasks > PDE Build"
I have encountered some issues during Xtext version upgrades with various dependency conflicts and Eclipse bugs. These can usually be resolved with the help of the Xtext dev team and then forcing certain dependencies in Gradle.
Unfortunately I can't share any of the build as it's a proprietary code, but I hope the explanation above is enough for anyone who needs to automate the process. It's certainly not a simple thing to set up though.

Add scalacheck dependency to gradle project

I am trying to use scalaCheck (https://github.com/rickynils/scalacheck) to a gradle project. However, adding it this way:
dependencies {
...
compile group: 'org.scalacheck', name: 'scalacheck_2.11', version: '1.12.5'
...
}
doesn't seem to be doing the trick. I also tried to add it in a maven project. In both cases, trying to do the following
import org.scalacheck.Prop.forAll
reports the error
object scalacheck is not a member of package org
I ran "gradle dependencies" before trying to import it, and it seemed to download everything just fine, finishing the command without throwing errors. Is there a way to add scalacheck to my project and if so, how?
Note: not sure if relevant, but I am using Eclipse Neon with all the scala plugins.
(So it seems the problem was with using the eclipse gradle integration.) You have to manually update the project by using the Gradle | Refresh Gradle Project from the project's context menu on each dependency change (though it might be useful to do that on each change to gradle configuration files).

Gradle dependency sources not appearing in Eclipse for the War Plugin

I am working on a Java web project that uses Gradle (version 2.1) as the build dependency tool. I use Eclipse Luna as my IDE. My OS is Mac 10.9 (Mavericks).
This is my build.gradle file (very basic and stripped down for ease of illustration):
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
sourceCompatibility = 1.8
version = '1.0'
repositories {
mavenCentral()
}
dependencies {
compile group: 'com.google.inject', name: 'guice', version: '3.0'
}
So just one dependency, Guice. I will generate my Eclipse classpath and project files using gradle cleanEclipse eclipse. Then I will import an existing project into my workspace. I like being able to view the source code of my dependencies in my Eclipse projects, so I will open a Guice class, such as com.google.inject.Injector, using CMD-SHIFT-T. And voila, the source code of that file will appear.
But I working on a web project, so I need to be able to build a WAR file instead of a JAR file. Therefore, I am going to apply the Gradle War Plugin by replacing apply plugin: 'java' with apply plugin: 'war'. Then I rerun gradle cleanEclipse eclipse and reopen my project.
Now, instead of seeing the source code when I open up Injector, I will see the bytecode viewer with the Attach Source button. Anyone have any ideas whether it's something I'm forgetting in my build.gradle file or if it could be a bug in Gradle/Eclipse?
Note that I am not using the Gradle Integration for Eclipse Plugin because I wish to pinpoint the root cause of this issue without adding an extra layer of complexity to it. I have also checked other SOF questions about Attach Source issue with Gradle and Eclispe, such as how to tell gradle to download all the source jars and Why is Eclipse not attaching 3rd party libs source files to a WTP-faceted Gradle project?, but to no avail.

Unable to make IntelliJ Idea 12 work with Scala compiler

I have installed Scala, sbt, eclipse and IntelliJ Idea 12. And also jdk, jre, etc. I'm able to run scala in Eclipse (Scala eclipse IDE) but I can't do it in Idea, even though I downloaded and installed scala plugin though Idea. Here is what I'm having at File -> Setting
and at a new project creation page
How do I solve these issues?
whereis scala
scala: /usr/bin/scala /usr/bin/X11/scala /usr/share/scala
which scala
/usr/bin/scala
I know I'm repeating this at any possible occasion—but your life will be much easier if you have sbt generate your IDEA project instead of trying to set it up manually. That will take care of configuring the modules correctly, so you are instantly ready to compile and run.
Here is a blog entry that might help. The section "How can I integrate libraries installed by SBT to IDEA?" tells you how to generate the project files.
Basically you need to create—starting from the root directory of your project—the file project/plugins.sbt with the following content:
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.4.0")
(you can also do that in the file ~/.sbt/plugins/build.sbt instead, that way you have the plugin available for any of your projects)
Then you run sbt gen-idea, and afterwards you can open the project directly from IDEA through File -> Open Project (and pointing to the project's root directory).
You could also generate your IDEA project with Gradle, which handles Scala+IDEA combination very well. Here's a minimal build.gradle script to do this:
apply plugin: 'scala'
apply plugin: 'idea'
repositories {
mavenCentral()
}
dependencies {
compile 'org.scala-lang:scala-library:2.10.1'
}
Just create a directory for your project, put build.gradle inside it, create src/main/scala subdirectory, then install Gradle and run gradle idea inside your project's directory. That should generate nicely configured IDEA project. With this method you don't even need to install Scala.
What exactly your problem is? I don't see anything on your screens which prevents you from using Scala in IDEA. Just select "Set Scala Home" radiobutton in "New project" dialog and then select your Scala installation path (I guess it will be /usr/share/scala). IDEA then will automatically create library and compiler libraries and add Scala facet to your project.