There is a command that lists all tasks (gradle tasks) accessible at project level which I am using very often when while working with Gradle. Is there a way to see properties available inside each of those tasks? I want to be able to do something like that:
gradle properties compileJava #this should list all properties available in **compileJava** task
One thing you can do is gradle help --task compileJava.
This will indicate which projects do define the compileJava task and also tell you what is the type of the task.
With this type, you can consult the DSL documentation to get information about the available properties.
There is no tool part of the Gradle CLI (at this time - Gradle 6.0.1) that will give you this in your terminal.
Many properties are not exposed via gradle help --task XXX. Use gradle model to get the list of all available tasks: it prints the class baking the task. Get the source code for the class.
Alternative way is via logging (run gradle bump):
tasks.register("dump") {
doLast{
logger.lifecycle("type: {}", bootJar.properties);
}
}
Related
Rest service : http://host:8000/v1/config/resources/removeCollection?put:database=string&put:uris=string*
I want to deploy this REST service extension in MarkLogic using gradle. How can I deploy this?
If you're already using ml-gradle, you can add your implemented interface to marklogic\src\main\ml-modules\services and deploy using the mlLoadModules task. The mlCreateResource task as part of the scaffolding would also add metadata in marklogic\src\main\ml-modules\services\metadata.
I recommend looking at ml-gradle. You can easily hook it up in gradle by adding a few lines, most importantly being:
plugins { id "com.marklogic.ml-gradle" version "4.0.4" }
As described in the readme, you can optionally follow that with invoking the mlNewProject task, which will provide you with a useful scaffold structure for a typical ml-gradle project.
ML-gradle gives you access to all kinds of tasks, including one called mlLoadModules to deploy source, and rest extensions. There is also a built-in task for removing collections in any database, called mlDeleteCollections. You can look at the Task-reference to get a glimpse of all the tasks, or just run gradle tasks.
HTH!
Two easy ways of plugin gradle to invoke REST API:
Method One:
If you don’t have any Project just yet,
create a gradle.properties file in which you define four parameters: host, mlUsername, mlPassword, RestPort
create a build.gradle file in the same folder:
plugins {
id "com.marklogic.ml-gradle" version "4.0.4"
}
task FCdeleteCollections(type: com.marklogic.gradle.task.datamovement.DeleteCollectionsTask) {
………………..
collections = ["{collection-name}"]
}
Invoke the gradle task:
[root# ~] # gradle FCdeleteCollections
Method Two:
If you already scaffolded the Project, in my opinion, it is safer to invoke one-time deletion task like this:
[root# ~] # gradle -Pdatabase={db-name} mlDeleteCollections -Pcollections={collection-name}
My preference is to invoke such task through Java API | DMSDK.
I want to write a script for following task in gradle. In IDE I run the task following way. When I want to add a custom task in the build.gradle file for the same. I wrote following script but it is giving me no such property: Classes for class: org.gradle.api.Project error . How to write the task I have in the screenshot using a custom script in gradle? Thank you.
task h2Continuous(type: Classes) {
args "--continuous"
}
There is not a Task type Classes. classes (lowercase) is a ad hoc declared task of the Java plugin, but not a unique Task type. It is an ad hoc task which wraps (via dependsOn) compileJava and processResources tasks. compileJava is a unique task type: JavaCompile.
If you are truly concerned with only java compilation, you could type your task as a JavaCompile task. There are multiple ways you could add in the processResources, if you really wanted your task to emulate the Java plugin's classes task.
Me and my team are working on a project with a lot of modules. We are using gradle for the project and everyone is new to gradle. We have a Main parent project i.e, parent build with the details of project dependencies. We want to add the integration_test task configuration to all the modules so that we can call the command gradle integration_test. So is there any way or concept of writing the configuration in the main module and make the child projects import the same configuration.
FYI: I tried it by directly adding it to the main project but got an error saying the classpath for the files which I specified does not exists. Any help or thought would be appreciated. Thanks in advance.
Is there a particular reason to split "integration tests" from the standard test task?
If so, you can run the same script for all subprojects from the main project's build file: https://docs.gradle.org/current/userguide/multi_project_builds.html#sec:subproject_configuration
For instance:
subprojects {
task integrationTest {
// whatever you need
}
}
I am note sure if this is what you talk about in the last paragraph. If so, please attache the error message you get.
It is also possible to "import" some configuration by subprojects, but the above definition is better in most scenarios.
It's easy to write a custom plugin and include it in the build script
apply from: "utilities.gradle"
For test purpose this file is in the same directory as the build.gradle
Calling a task defined in utilities.gradle from build.gradle works without any hassle.
In utilities gradle is also a plugin defined - configuring it from build.gradle just works.
But if I define a custom task in utilities.gradle calling it is no problem but if I want to use that custom taks in build.gradle it says
> Could not find property 'GreetingTask' on root project 'TestGradle'.
utilities.gradle:
task hello(type: GreetingTask)
class GreetingTask extends DefaultTask {
#TaskAction
def greet() {
println 'hello from GreetingTask'
}
}
build.gradle
task hellox(type: GreetingTask)
Ok... I read the documentation here: http://www.gradle.org/docs/current/userguide/custom_tasks.html
It says the custom task is not visible outside...
But then... how to share custom tasks with the team without making a Jar for everything.
What I want is to place the utilities.gradle on a network drive and share it with the other.
pls help
There is a special $rootDir/buildSrc directory which is its own build. All classes that this build produces are available to all build scripts in the "main" build. The buildSrc build has a default build.gradle, but you can add your own. By default, Java classes are expected under src/main/java, and Groovy classes under src/main/groovy. You can read more about buildSrc in the Gradle User Guide.
To share classes across multiple builds, a separate plugin project that publishes a Jar is the way to go.
I'm working on a project that uses EJB2s. The created EJB Jars require additional processing by the application server before they're bundled in the war/ear and deployed.
I have created a custom task that works to do the additional processing if I invoke it explicitly (gradle ejbDeploy), but am having trouble fitting it into the gradle multi-project lifecyle. I need to somehow add it to the build graph to execute automatically after the jar task.
My first attempt was to add it to jar with
jar.doLast{
ejbDeploy.execute()
}
which seems to work for arbitrary code blocks, but not for tasks
What's the recommended solution for this? I see three approaches:
Hook into the build graph and add it explicitly after the jar
task.
Set it up somehow in jar.doLast{}
Set it up as a prerequisite for the WAR task execution
Is there a recommended approach?
Thanks!
I would go for approach #3 and set it up as a dependency of the war task, e.g.:
war {
it.dependsOn ejbDeploy
...
}
I'm new to Gradle, but I would say the answer really depends on what you're trying to accomplish.
If you want to task to execute when someone runs the command gradle jar, then approach #3 won't be sufficient.
Here's what I did for something similar
classes {
doLast {
buildValdrConstraints.execute()
}
}
task buildValdrConstraints(type: JavaExec) {
main = 'com.github.valdr.cli.ValdrBeanValidation'
classpath = sourceSets.main.runtimeClasspath
args '-cf',valdrResourcePath + '/valdr-bean-validation.json'
}
Add the following, and then ejbDeploy will be executed right after jar, but before war
jar.finalizedBy ejbDeploy
See Gradle Docs. 18.11. Finalizer tasks