Why is my IDEA gradle.build script not importing Guava? - java

I have never really done build automation before, but I'm trying to learn how to use Gradle. I never was interested in build automation but I'm finding it increasingly necessary nowadays.
I'm trying to create a new IDEA project. It has some dependencies on Guava immutable collections. I implemented the following gradle.build script.
But no matter how I try to run the build, or clean/rebuild the project... the Guava library never seems to be included in the project and the compile errors remain.
What exactly am I doing wrong? What tasks am I missing to get this to compile with all the dependencies?

Open Gradle tool window and click refresh button.

Related

How to automate Gradle task running

The project I am working on is Java, Gradle based. So I want to create a plugin/script that will run a certain Gradle task whenever I made changes to one of the files from the project.
For example
There is A.xml file and a B Gradle task. Whenever I do changes to A.xml and save it I want the B Gradle task to be run.
I am using IntelliJ IDEA, and my initial thoughts are that it could be solved through plugins/scripts.
Can you suggest where to start? Should it be done through plugins? Maybe there are automatisation settings in IntelliJ that have file watchers or smth. Thanks.
I tried to search similiar plugins, and didn't find any. Read documentation for plugin creation, I think I can reach the result, but isn't it overhead?

Installing a framework without maven or gradle

I try to install Javalin framework for creating an API on my Java project. (old java 8 project without maven, gradle, etc). I would like to install the framework with adding the jars to my build path.
But If I add the main jar file then it needs another dependencies jar , then another one another one another one.. etc.
Is there any simple way to add this to my project and all it's dependencies without any build tool like Maven,etc?
I have tried adding it manually , but each jar has many dependencies that it is almost impossible(?)
Well you could create a Maven project and use it to download the dependencies for you.
Maven dependency plugin might be useful. With it you could just call:
mvn dependency:copy-dependencies
and it will download all your dependencies into target/dependency.
I don't think there's a way, I'm afraid.  Dependency management is the exact problem that build tools like Maven and Gradle were created to solve!
The framework supplier could provide a ‘fat’ jar including all the dependencies; but I'm not aware of any that do, as everyone uses Maven or Gradle (or SBT or Ivy or Grape or Leiningen or Buildr).
I think the only real alternative is to do it manually — which, as you've discovered, can be a horrible and lengthy task if the dependency tree is big.  (And would need redoing with every update.)
So I'd suggest biting the bullet and using Maven if you can.

difference between Gradle and accurev

Can any one explain the difference between Accurev and Gradle.
I am trying to use it in eclipse mars version.
I have a project got from AccuRev how can I import it as a gradle or as AccuRev?
Here you go.
AccuRev -> https://en.wikipedia.org/wiki/AccuRev_SCM
Gradle -> https://en.wikipedia.org/wiki/Gradle
AccuRev is not a build system or project format, it's a source control management system like cvs, subversion, git, tfs, mercurial etc.
Gradle is a build system and project format similar to maven, but with groovy scripting, so you essentially get the declarative style of maven plus the imperative style of ant.
You would keep/promote a gradle project to AccuRev, but you would need to create the gradle project first.
So first things first you need to figure out what kind of project you already have as that has not been determined.
It's pretty simple, a little search on your favorite search engine could help you to understood :
AccuRev: Versioning tool (like git)
Gradle: Build tool (like maven)

How to properly import a Gradle project into IntelliJ with dependencies

So, I have a fairly basic Gradle project. Everything works fine through Gradle using either "test" or "build". However, when I go to actually import this project into IntelliJ, everything seems to be added as expected except none of the dependencies make it into the build process. The Gradle tool window clearly lists the dependencies used and such, but actually trying to use these ends up with none of the packages being found. I've tried resyncing it, cleaning and rebuilding, etc. But it always ends up with none of the dependencies actually being there in IntelliJ's build process. Building from Gradle is fine.
How can I resolve this!? I tried using the "idea" plugin with the "ideaModule" task. This puts all the dependencies into there as I expect, but also overwrites all of the changes that I made (such as excluded/included source files)... And I'd need to make sure to manually run it any time I change dependencies
How can I get IntelliJ to actually recognize and build with the dependencies in the Gradle build file?

How to make IntelliJ IDEA use javac for Java and scalac for Scala?

In my IDEA project a Scala module depends on a Java module. When I try to compile the Scala module, only scalac is triggered. It compiles both Java and Scala sources.
I'd like scalac to compile only the Scala module, because javac is much faster for Java sources (and my Java project is a big one).
How to make IDEA use different compiler for different modules?
My workaround is to (for each dependency to Java module):
Delete module dependency in project configuration
Add dependency to appropriate compile output directory "MyJavaModule/target/classes"
Obviously I'm not happy with that, because every time I reimport Maven project I need to repeat all of this to have fast compilation. I hope somebody knows a better way.
Clarification: I'd like to stress, that tools like SBT or Maven don't solve my problem. It is not about compilation alone. It's about compilation in IDEA, required for things like Scala Worksheet or running unit tests from IDEA. My goal is to have full range of IDEA niceties (syntax highlighting, intelligent auto-completion, auto-imports, etc) with compilation speed of SBT. Now I have to either tolerate long compilation times (due to dependencies to my Java module) or to use bare-bones REPL and testing in SBT.
Randall Schulz has asked the right question in the comment: "Why does it matter which tool does the compilation?"
Up until now I believed that IDEA needs to compile all classes itself if you want to use its nice features (like IDEA's Scala Console or running tests from within it). I was wrong.
In fact, IDEA will pick up classes compiled by any other tool (like the great SBT for instance). You just need to assure that all classes are up-to-date before using any of IDEA's helpful features. The best way to do it is:
launch continuous incremental compilation in the background (for
example by issuing "~ compile" in SBT)
remove "make" step in IDEA's
run configurations
That's all! You can then use all cool features of IDEA (not only syntax highlighting and code completion, but all auto-imports in Scala Console, quickly running selected unit tests) without switching between different windows.
That's the workflow I missed until now! Thanks to everybody for all the comments about the issue.
You should look at using a dependency management suite like Apache Ivy or Apache Maven. Then put your Java source in a separate artifact, and have your Scala project be dependent on the Java project artifact.
If you go the Maven route, there is a Scala plugin.
Probably the simplest way to get compiled Scala and Java files is SBT - Simple Build Tool. Just create a project (+ add dependencies and so on) and compile it. Scala + Java compilation works out of the box. I've switched to SBT from Maven.
If you have a complex POM or if you have another reason not to migrate to SBT, you can try to configure the POM. Just adding (and possibly configuring) the Scala plugin should be enough. I hope it will not break the Java support.

Categories