There is no documentation if you want to create your own plugin. David is
correct in that you should use the plugin gradle plugin and his example is
great.
I believe in learning with code and the plugins in the core repo are
difficult to learn by, ironically even the example one, because they depend
on the rest of the gradle build defined at a higher level. Here is a simple
example, with an additional fixture if you want to test against external
resources: https://github.com/brusic/plugin-with-fixture-skeleton
Hi, I was trying to start elastic search instance from this sample library.
I have nothing in my repository except this gradle file
buildscript {
repositories {
mavenLocal()
mavenCentral()
jcenter()
}
dependencies {
classpath "org.elasticsearch.gradle:build-tools:6.1.1"
}
}
apply plugin: 'java'
apply plugin: 'elasticsearch.esplugin'
apply plugin: 'idea'
apply plugin: 'maven'
// this is temporal and will be fixed in 6.0
ext.projectSubstitutions = [:]
// license of this project
licenseFile = rootProject.file('LICENSE.txt')
// copyright notices
noticeFile = rootProject.file('NOTICE.txt')
esplugin {
// license of the plugin, may be different than the above license
licenseFile rootProject.file('LICENSE.txt')
// copyright notices, may be different than the above notice
noticeFile rootProject.file('NOTICE.txt')
name 'ESTest'
description 'TestingESGradle'
classname 'ESTest'
}
repositories {
mavenLocal()
mavenCentral()
jcenter()
}
// In this section you declare the dependencies for your production and test code
// Elasticsearch dependency is included due to the build-tools, test-framework as well
dependencies {
testCompile 'org.elasticsearch.client:elasticsearch-rest-high-level-client:6.1.1'
}
integTestCluster {
setting 'clusterName', 'GetProductTest'
setting 'version', '6.1.1'
setting 'httpPort', '9400'
}
artifacts {
archives javadocJar, sourcesJar
}
I am getting this error when running the command gradle run.
I want to start a new Elasticsearch instance when I run test in my java project.
So basically I have a gradle task for test, which should first spin up elasticsearch instance and then perform tests on it.
I got it how to run the gradle task, but I dont understand how do I integrate it with my project which already has gradle run task,
I want tasks of these plugin to run in my main project test task.
I joined the conversation late and did not fully read your original
intention. I simply thought you wanted to use the plugin plugin.
That plugin is meant to develop plugins, but it probably can be repurposed
to simply run integration tests. Your integration test gradle task would
need to depend on the integTestCluster task. I do not think you will be
able to use the clients though, so you will need to make sure that the test
cluster starts on a port you are expecting. Perhaps there is some
elasticsearch project that already has this behavior.
@prakharjain17 If you only want an integration test cluster, then Ivan is correct: applying the elasticsearch.esplugin gradle plugin is incorrect. Instead, you will want to use the elasticsearch.rest-test plugin. Then, you can create a task of type RestIntegTestTask, which automatically creates the cluster configuration extension. You should look at the client smoke test as an example.
so you will need to make sure that the test
cluster starts on a port you are expecting. Perhaps there is some
elasticsearch project that already has this behavior.
@Ivan Actually, the port does not need to be hardcoded. The cluster that is configured by the RestIntegTestTask has a special flag passed to elasticsearch which instructs the node to write its http and transport bound ports to special log files. The gradle code then reads these files after the cluster is started, and passes them as a system property to the test runner. This allows us to use ephemeral ports for all our testing, and we can run with --parallel and not get any race conditions across integ test runs.
This line needs to be removed: apply plugin: 'java'
The standalone-rest-test plugin creates a test sourceset. If you want to include your project's jars, do that with a dependency on your jar in this project (ie you will need multiple projects).
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.