How to have intellij use gradle build directory instead of out - java

I have a Gradle plugin that generates some resources in build/resources directory. When I run the program from within IntelliJ it doesn't find the resource on classpath.
Intellij uses out directory instead of gradle's build. build is only used by gradle tasks such as jar etc. Both build and out hold duplicate copies of the compiled Java files.
How do I have Intellij use the same directory as Gradle for compilation output?

Figured this out after a while.
Under Build, Execution, Deployment -> Build Tools -> Gradle -> Runner select Delegate IDE build/run actions to gradle.
This makes IntelliJ delegate its build operations to gradle instead of using its own compiler. The out directory would no longer be generated and build would be put on the classpath when you run a class.
I haven't noticed any performance differences. Probably since Gradle too uses incremental compilation and a daemon for faster subsequent builds.

Related

How to call Gradle build task from Gulp build running in Node.js environment

I have added Gradle to my project to manages Java dependencies, it basically fetches all the jars from maven and then runs a copy task to copy all the jars to a destination folder.
I run the Gradle from the command line at the project root folder:
gradle build //fetch all the jars
gradle copyJarsToDest //a custom Gradle task to copy all the runtime environment dependencies
Now I am asked to integrate my Gradle task into an existing Gulp Build task. The Gulp Build is running in Node.js environment and uses Babel for the latest JavaScript features. The Gulp Build pulls the code from Git repository, compiles the JavaScript and Java code, then put them into jars that can be deployed to our servers. When I start to look into how to call my Gradle task from Gulp, I only see the various posts about calling Gulp from Gradle, nothing on calling Gradle from Gulp.
Any ideas on how to call Gradle within Gulp? I am new to Gulp, I don't know if there is a way for me to ask Gulp to execute command lines "gradle build" and "gradle copyJarstoDest"? Many thanks.

Difference between "IntelliJ", "Maven" and "Gradle" build system in IntelliJ IDEA?

What is the difference between IntelliJ, Maven and Gradle build system in IntelliJ IDEA?
Has IntelliJ IDEA its own build system?
In addition, what is the difference between run in IntelliJ and Gradle bootRun?
Build project is IntelliJ's own build-in build mechanism, it simply compiles all modified and dependent files in the project.
However, it's a "plain vanilla" build. It doesnt do fancy things like creating artifacts, deploying to repositories, codegen from a wsdl - etc. That's what we use build automation tools for, and there are 2 of them (maven and gradle) in widsepread use.
Maven and gradle allow developers to set up a custom (and more complex) build configuration.
The maven pom.xml defines lifecycle goals and the gradle build.gradle defines tasks.
Via a plugin architecture, maven / gradle can accomplish almost anything in a build process. Whilst the maven / gradle "run" task can operate similarly to IntelliJ "Build Project", it's not the same thing - in this case the build is instrumented by the build tool (maven or gradle) and can be configured differently, and be part of a more complicated build process.
What is difference build project in IntelliJ and gradle build?
IntelliJ build uses IDE's own jps project model and builder for compiling the java-based projects. Including incremental build support.
With Gradle build it actually uses Gradle to build the project (think Gradle build task).
In addition, What is difference run in IntelliJ and gradle bootRun?
Basically same as above: IntelliJ runner - uses build results of IDE's builder and IDE's own Run/Debug Configuration to launch the application ant tests. With Gradle runner - IDE delegates this to corresponding (bootRun) Gradle task.
See also Configure the build and run actions for additional details.
I tested this locally in my project, using two builds: one using IntelliJ IDEA's "build project" and the second using Gradle's own build command.
Then I checked the contents of the .build directory in my project and found that the former (IntelliJ IDEA's build) produced less files than the latter (Gradle). I think Gradle's build system is more powerful than IntelliJ IDEA's, which is why I prefer to use Gradle in my projects.

What exactly IntelliJ is doing when compiling project using Gradle?

IntelliJ IDEA 2016.3 add the ability to delegate build/run to Gradle.
It's clear that when the delegate option is on Gradle is doing everything.
My question is what exactly IntelliJ is doing when this option is off?
I'm asking this because I have custom code inside my Gradle files and it does not seems like this code is executed when building in IntelliJ. When I run gradlew build everything works just fine.
IntelliJ has its own build system, called JPS, which uses the IntelliJ IDEA project and .iml files as the project model. When you're using IntelliJ IDEA's default build system to build the project, it does not execute any code in Maven or Gradle files; it uses its own logic, which can only be extended by writing plugins to JPS.

How to prevent IntelliJ from asking to provide the Scala SDK after every Gradle build?

I'm using IntelliJ IDEA (15.0.3) to write a project in Scala over Spark.
Every time I build using the following command
./gradlew clean build idea
IntelliJ pops up the message 'No Scala SDK in module' and asks to setup the Scala SDK version.
Is there a way to permanently specify the SDK version so that building with Gradle won't override it?
In general you don't need to run the idea task with every build. That task generates IDEA project files so you're able to open the project from within the IDE - you usually only need to run it once when setting up the project. Running the task over existing project files can (partially) overwrite them, depending on how the task is configured and apparently does override the SDK configuration changes made in your case.
So just running ./gradlew clean build when building should solve your issue (unless I'm missing/misunderstanding part of your question).

Intellij Idea compiler recompiles already compiled project

I use maven command which cleans,builds whole project, creates war and deploys to server. I cannot use Intellij to do that since I have only Community edition. It builds the project in same directory as intellij.
To speed things up I wrote a script which finds compiled files in local "target" directory which are newer than the ones in server and copy them. It all works okay but the problem is Intellij does not see classes compiled with maven as the ones it should skip and rebuilds whole project all over.
Currently it works like this:
Manually in terminal build whole project with maven
Go back to intellij -> make project
Rebuilds all
Run script -> it swaps all files
What I am trying to achieve:
Manually in termin build whole project with maven
Go back to intellij. Change one file -> make project
Compiles only one java file
Run script -> it swaps only one .class file
So the problem is how do I make intellij treat files already compiled with external tool as compiled?
You don't. IntelliJ IDEA has its own incremental compilation system which tracks the dependencies between files being compiled and recompiles the minimum set of classes for every set of changes. External compilation with tools like Maven or Gradle does not update IntelliJ IDEA's incremental compilation database. Because of that, IntelliJ IDEA cannot recognize the fact that classes have been already compiled with an external tool, and will recompile.
That troubled me for long time. Finally, i found this .
IDEA build settings
You can choose whether use InteliJ or gradle to compile when runnning program. Under gradle project, it uses gradle to build by default.

Categories

Resources