Gradle: What is the difference between the tasks 'build' and 'buildSearchableOptions'? - gradle

I am building a plugin in IntelliJ and Gradle, and have the following question:
What is the difference between the predefined tasks build and buildSearchableOptions in Gradle?
I can see that :buildSearchableOptions is called as part of :build and that it produces its own JAR file.

They come from two different plugins.
Assuming a Java project, the build task comes from the java plugin which in turn comes from the life cycle/base plugin:
https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/java/org/gradle/api/plugins/JavaBasePlugin.java#L74
https://docs.gradle.org/current/userguide/base_plugin.html
The buildSearchableOptions task comes from the org.jetbrains.intellij plugin:
https://github.com/JetBrains/gradle-intellij-plugin/blob/master/src/main/groovy/org/jetbrains/intellij/IntelliJPlugin.groovy#L350..L360
https://github.com/JetBrains/gradle-intellij-plugin#tasks

Related

Gradle: Depend on artifacts from ant legacy build

I am wondering how to declare a dependency on artifact produced by a legacy Ant build.
I have a Gradle build that consists of 2 modules: 'legacy' and 'backend'.
The 'legacy' module is quite old, requires an Ant to generate a 'legacy/dist' directory. I cannot convert this build to Gradle, unfortunately. This build takes a lot of time. For convenience, the Ant build is wrapped as a Gradle build.
The 'backend' module uses the 'war' plugin. It needs to package 'legacy/dist' directory into the war.
legacy/build.grade:
ant.importBuild 'build.xml'
current backend/build.grade:
plugins {
id 'war'
}
dependecies {
?
}
war {
dependsOn ':legacy:dist'
from('../legacy/dist')
}
This solution works, but has several drawbacks. To force Gradle to build 'legacy' before 'backend', I stated that the :backend:war task depends on the :legacy:dist task (not recommended). Every time I build backend, Gradle cannot know if legacy was build and calls :legacy:dist task, triggering unnecessarily the legacy build that takes a lot of time.
How should I declare on legacy/build.grade that it generates the dist directory and that the backend/build.grade depends on this dist directory? Without depending on tasks and without mentioning directory explicitly? I could figure out how to accomplish this from the documentation. Thanks.

Is there a way to configure Gradle plugin to execute task with build?

I apply my custom plugin to project:
plugins {
id 'my.plugin.gradle-plugin' version '1.0.0'
}
This plugin contains task runMe and I want to always execute it only with build task.
The way to get it specifying in my root project:
build.dependsOn runMe
But I want to get this behavior by setting up the plugin once and don't repeat this every project which uses the plugin.
What you can do is to check in apply method if build task already exists. If so you can define a dependency there. Otherwise it's impossible.
Also, where does the build task come from? Another plugin? If so apply this plugin in you plugin and then define the dependency.

How to enable and disable clover plugin in gradle for root project

We have multi project setup and am using clover plugin for code coverage of Java process. the subprojects are of Java and Scala. When I apply the clover plugin in build.gradle of root project and run the unit test, the clover plugin is also applied on subprojects which are in Scala. I dont want to manually update the build.gradle of all the subprojects
Do we have a way of enabling and disabling a plugin in gradle ? ( I am asking so that by default we can have the plugin as disabled. When we run the code coverage task at that time we can enable it )
Or is there any other way of solving it.
Note: I have enabled the clover plugin at the build.gradle at root level and in those subprojects which are written in Java

How to get insight of a dependency for the "implementation" configuration?

Based on documentation (4.7.6 - Getting the insight into a particular dependency) we can get the insights for a particular configuration specifying the configuration itself.
In the example they are using as configuration compile, which is deprecated.
I tried to reproduce the same command replacing, in build.gradle, the compile configuration with the implementation configuration (as I got we are not supposed to use compile anymore).
But when I run:
gradle dependencyInsight --dependency groovy --configuration implementation
Gradle is returning:
Execution failed for task ':dependencyInsight'.
Resolving configuration 'implementation' directly is not allowed
My build.gradle file is the following:
apply plugin: 'java-library'
repositories {
jcenter()
}
dependencies{
implementation 'org.codehaus.groovy:groovy-all:2.4.10'
}
Does it mean I cannot get the insight of a dependency if I'm using implementation or is there another way to get it?
I had a similar problem, asked around and got this answer:
The configuration is compileClasspath. If you have variants, there is a configuration per-variant (e.g. for the release variant, your configuration would be releaseCompileClasspath).
Examples
No variants: gradle dependencyInsight --dependency groovy --configuration compileClasspath;
Release variant: gradle dependencyInsight --dependency groovy --configuration releaseCompileClasspath
Note
There are a few ways to figure out the available configurations.
If you add configurations.each { println it.name } to your top-level gradle file, the next time you run a task, you'll also get a list of all of your configurations.
Run the dependencies task on your top-level module - this will output all dependencies for all configurations. It can be a lot of text, so you could pipe it into a text file for easier searching (gradle dependencies > dependencies.txt)
To get the list of available configuration that can be used with dependencyInsight, the easy way is the following :
Open gradle view in android studio View > Tool Windows > Gradle
Select and run task 'Your App' > Tasks > Android > androidDependencies
Then you have a list of all dependencies for all available configuration, just pick one and run :
gradle :mymodule:dependencyInsight --dependency okhttp --configuration flavourDebugCompileClasspath
Hope it helps

Using Gradle project-report and jacoco plugins together

I'd like to use both the Gradle project-report and jacoco plugins in my project. To illustrate the problem I'm having though, I opened build.gradle at: gradle-1.7-rc-1/samples/testing/jacoco/quickstart and modified it to be:
apply plugin: "java"
apply plugin: "jacoco"
apply plugin: "project-report"
running a gradle projectReport then gives me the error:
gradle projR
:dependencyReport
:propertyReport
:taskReport FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':taskReport'.
> Could not determine the dependencies of task ':jacocoTestReport'.
Any advice on how to get these two plugins to play nice together would be appreciated (note, they both work independently of each other).
Thanks
Covered by GRADLE-2917, will be fixed in version 1.10 as described in the Gradle Forum

Resources