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

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.

Related

Unable to run Maven project (gephi-app) the same way on NetBeans in IntelliJ

I am currently working on a project that involves utilizing Gephi's backend tools and frontend visualizers. For this, I have cloned Gephi's repository, https://github.com/gephi/gephi.git. The following tutorial walks users through how to clone and modify Gephi's sourcecode so that you may add "circle creation logic" to Gephi's visualizer, https://seinecle.github.io/gephi-tutorials/generated-html/working-from-the-source-en.html. I have found that running the project through NetBeans is a straightforward process, build the dependencies and run.
Unfortunately, such an option doesn't exist in IntelliJ and the maven "Lifecycle" goals that I can run (clean, validate, compile, test, package, verify, install, site, and deploy) build successfully, but does not actually run the project within the environment unlike NetBeans does. I am wondering what I am missing here, or how NetBeans can simply run the maven project node, but such an option doesn't exist in IntelliJ? How do I perhaps edit my run configuration within the IntelliJ IDE so that I can run such an instance?
The equivalent in IntelliJ IDEA would be the following:
Run the compile goal
Run nbm:cluster-app
Run nbm:run-platform
The last 2 goals are provided by the nbm Maven plug-in.
In IntelliJ IDEA they are visible under the Plugins node of the module in the Maven tool window:

How to have intellij use gradle build directory instead of out

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.

Why does 'Build Project' fail whereas Run (Maven configuration) succeed?

Case in question: A Maven based project that has a Maven Run Configuration with its 'Command line' parameters defined as clean install.
Clicking the green arrow to invoke 'Run my_maven_config' downloads all necessary packages from Nexus and completes the build successfully.
Selecting 'Build Project' however, invokes a seemingly similar process but after building successfully for quite a while, it fails on a missing Hibernate package.
Why is this difference?
Shouldn't the build part of 'Run' be identical to the "standalone build"?
They are not identical. IntelliJ IDEA imports the external project model from Maven and converts it to the internal project model. It's not 100% accurate, some Maven plug-ins are not supported, some dependencies may fail to resolve, etc.
See this answer to perform the diagnostics. Try re-importing the project (delete .idea directory first if it doesn't help).
Delegating build/run actions to Maven as it can be done now with Gradle will be supported later (probably in IntelliJ IDEA 2018.3).
Now IntelliJ IDE allow to delegate Build actions to maven.
Go to Preferences and search for "Delegate IDE build actions to maven".
So when you build a project, IntelliJ IDEA invokes the appropriate Maven goals.

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.

Gradle: Comparing maven and gradle artifacts built from the same source

There's an incubating feature in gradle for comparing builds (documentation here). The documentation states it can compare:
A Gradle build with a build executed by another tool such as Apache Ant, Apache Maven or something else (i.e. migrating to Gradle).
I'd like to use this feature but the documentation doesn't outline how to do it. I'd like to build the same source code twice, once with maven then with gradle and compare the built artifact (a jar).
I've generated a build.gradle using gradle-init --type pom now i'd like to
Run the gradle build (build.gradle)
Run the maven build (pom.xml)
Compare the jars built by both
I don't mind if I need two duplicate copies of the source code to achieve this. I'd like to automate the process so that it's repeatable as I migrate my build from maven to gradle.

Categories

Resources