How to run pre build gradle java project in intellij - eclipse

I have been using eclipse. Recently, I started using intellij IDE.
My project is core java project with gradle as build tool. In eclipse, i used to build the project through command like and import it into the project. Then i used to run it without any issues.
One of the below command i used to use frequently.
gradle -s --refresh dependencies clean build eclipse -x findbugsMain -x checkstyleMain
gradle -s --refresh dependencies clean build -x findbugsMain -x checkstyleMain
gradle build -x findbugsMain -x checkstyleMain
Now when i try imported my projects as module in intellij and try to run, it tries to build everything again and fails with error.
I do not want intellij to build the project again but to use the already build one which i did through command line.

If you build form command line first, then build from IDE with Settings (Preferences on macOS) | Build, Execution, Deployment | Build Tools | Gradle | Build and run using option set to Gradle, IDE will reuse previous build cache results, provided that there were no changes since last Gradle build. It is important to note 2 things:
Build from IDE should be invoked as Build | Build action, not Rebuild. The Rebuild IDE action is not the same as Gradle clean build task. With clean build Gradle will re-use cache (if enabled) and will not rebuild all the classes and process all the resources if there were no changes. In case of the IDE Rebuild action - IDE will mark previous build results as "dirty" and will recompile all the classes and resources.
The Gradle you configure for the project in IDE settings must be the same as you use in command line. To be sure the same Gradle is used it is easier of all to configure to use Gradle wrapper for project.
Also if you do not want for the IDE to build at all you can remove Make action from Before launch section of your Run/Debug Configuration.

Related

How do I set up my JavaFX project as a Gradle build?

I've created a new JavaFX project via the e(fx)clipse plugin, then staged and committed to Git. Following that I tried to run it and got a 'class not found' error - needed to add JavaFX to the --module-path in VM arguments. But it still won't run:
Error: Could not find or load main class Files\Java\AdoptOpenJDK\javafx-sdk-13.0.2\lib
Caused by: java.lang.ClassNotFoundException: Files\Java\AdoptOpenJDK\javafx-sdk-13.0.2\lib
Then I noticed that I have no build files in the project tree - no pom.xml or build.gradle, etc.
I decided to build with Gradle (previously only used Maven). After a lot of hunting on the net I did the following:
Project context menu -> Configure -> Add Gradle nature (this didn't visibly do anything, but the option is no longer available).
In the Gradle Tasks view, run init. (This ran fine until it got to Execute setupProjectLayout for :init. This got stuck and I let it sit for about 20 mins, but there was no activity (checked task manager to confirm)).
There must be something fundamental that I'm missing here, surely it shouldn't be this difficult. How can I get this project to build in Gradle?
The Gradle init task is an interactive task to generate a new Gradle project. If you run it from the IDE but have no way to provide answers to the prompts from Gradle, it will indeed wait forever on an input.
You do not need a CLI for input.
After you run the gradle task in the "Gradle Tasks" view you switch to the "Console" view and you are presented with the questions by gradle init. You answer those questions and finish the task.
Working Directory: /path/to/your/project/thenewgradleproject
Gradle user home: /home/user/.gradle
Gradle Distribution: Gradle wrapper from target build
Gradle Version: 6.8
Java Home: /usr/lib/jvm/java-11-openjdk-amd64
JVM Arguments: None
Program Arguments: None
Build Scans Enabled: false
Offline Mode Enabled: false
Gradle Tasks: init
> Task :wrapper UP-TO-DATE
Select type of project to generate:
1: basic
2: application
3: library
4: Gradle plugin
Enter selection (default: basic) [1..4]
> Task :init
Select build script DSL:
1: Groovy
2: Kotlin
Enter selection (default: Groovy) [1..2]
Project name (default: thenewgradleproject):
> Task :init
Get more help with your project: Learn more about Gradle by exploring our samples at https://docs.gradle.org/6.8/samples
BUILD SUCCESSFUL in 53s
2 actionable tasks: 1 executed, 1 up-to-date

Gradle Build Configuration help - Eclipse Oxygen

I'm using eclipse oxygen and i was trying to run Gradle Buid on build.gradle file. I have installed Buildship Gradle Integration 2.0 and also configured the dependencies. The issue is when i right click on build.gradle and try to run as, i don't have the option Grade Build.
Instead of right-clicking the build.gradle file use the Gradle Tasks view to execute a Gradle task:
Window > Show View > Others...: Gradle > Gradle Tasks
Double-click a task
See also my short video on how to execute a Gradle task.

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).

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.

How to set up IntelliJ external Scala compiler for Maven projects

I'm using IntelliJ 13 community version. I have a Maven project with multiple modules.
Currently, I'm using IntelliJ internal compiler. I find that every time I run maven clean XXX, I have to manually trigger Scala rebuild in IntelliJ before I run any Cucumber acceptance tests. Otherwise IntelliJ will complaints "no class file". It is annoying. It takes 2 to 3 minutes for the clean re-build.
Finally, I decide to try the external compiler. I have no idea how to do it. I does not seems as easy as enable external compiler.
Can any one please teach me how to properly set up external compiler for a multi-module maven Scala project?
Maven clean command deletes your jar and target folder.
therefor you need to compile the maven project with the maven command "compile" / "install" after clean .
if you want to use your command line to clean and compile you can run $ mvn clean compile . but actually since "clean" is the 1st step at maven's build life cycle you only need to run the compile command . it will run "clean" (or $ mvn compile) as the 1st step of the build .
check out maven build life cycle here