How can I use a custom 3rd party artifact in ElasticSearch locally ?
From docs
Update the dependency declaration of the artifact in question to match
the custom build version. For a file named e.g. jmxri-1.2.1.jar the
dependency definition would be :jmxri:1.2.1 as it comes with no group
information:
But I get an exception because getGroup returns null
Steps to reproduce
clone elasticseach into /tmp
create a directory /tmp/elasticsearch/localRepo
add to (root) build.gradle allprojects here the following
allprojects {
repositories {
flatDir {
dirs 'localRepo'
}
}
}
my local jar is /tmp/elasticsearc/localRepo/test-3.2.1.jar
add here
api ':test:3.2.1'
run ./gradlew localDistro
Error message
FAILURE: Build completed with 2 failures.
1: Task failed with an exception.
-----------
* Where:
Build file '/tmp/elasticsearch/client/sniffer/build.gradle' line: 41
* What went wrong:
A problem occurred evaluating project ':client:sniffer'.
> Cannot invoke "String.startsWith(String)" because the return value of "org.gradle.api.artifacts.Dependency.getGroup()" is null
2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':client:sniffer'.
> Cannot invoke "java.lang.Comparable.compareTo(Object)" because the return value of "java.util.function.Function.apply(Object)" is null
BUILD FAILED in 925ms
19 actionable tasks: 19 up-to-date
Dependencies always need a group set like
"group:module:version"
You also need that for flatDir repositories but the group doesn't matter and can be anything as far as I know. I used "test" in the example below
repositories {
flatDir {
dirs(" /tmp/elasticsearch/localRepo")
}
}
dependencies {
api 'test:test:3.2.1'
}
Related
I have a multimodule project that I am trying to use gradle 7.5.1 and jib to build and deploy each service artifact to ECR.
I have a ~/.docker/config.json file
{
"credsStore": "desktop"
}
{
"credHelpers": {
"public.ecr.aws": "ecr-login",
"xxxxxxx.dkr.ecr.us-east-1.amazonaws.com": "ecr-login"
}
}
and my AWS keys are in ~/.aws/credentials
Each of my modules has a settings.gradle that defines the rootProject.name to be the service (artifactId), as well as the plugin 'maven-publish'.
In my main project I have a build.gradle:
plugins {
id 'java'
id 'groovy'
id 'com.google.cloud.tools.jib' version '3.3.0'
id 'maven-publish'
}
..
jib {
from {
image = 'azul/zulu-openjdk:17-jre'
}
to {
image = 'xxxxxxx.dkr.ecr.us-east-1.amazonaws.com/${rootProject.name}'
// I have also tried image = 'xxxxxxx.dkr.ecr.us-east-1.amazonaws.com/${artifactId}'
}
}
When I try to build them via gradle jib I get the following error:
> Task :jib FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':jib'.
> Invalid image reference xxxxxxx.dkr.ecr.us-east-1.amazonaws.com/${rootProject.name}, perhaps you should check that the reference is formatted correctly according to https://docs.docker.com/engine/reference/commandline/tag/#extended-description
For example, slash-separated name components cannot have uppercase letters
The stacktrace also mentioned the invalid reference.
I am following several tutorials and the Google jib documentation, but I do not see what I am doing wrong - anyone else know?
Use double quotes instead of single quotes to make Gradle expand properties.
When I try to declare the task "build" depends on another task like this:
task("build").dependsOn(
gradle.includedBuild("splain").task("publishToMavenLocal")
)
I got the following error:
FAILURE: Build failed with an exception.
* Where:
Build file '/home/peng/git/shapesafe/build.gradle.kts' line: 35
* What went wrong:
Cannot add task 'build' as a task with that name already exists.
How to fix it?
UPDATE 1: this also doesn't work:
tasks {
build.dependsOn(
gradle.includedBuild("splain").publishToMavenLocal
)
}
e: /home/peng/git/shapesafe/build.gradle.kts:92:15: Unresolved reference: dependsOn
UPDATE 2 the following compiles successfully, but gives a different error:
tasks.build{
dependsOn(
gradle.includedBuild("splain").task("publishToMavenLocal")
)
}
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':core:compileTestScala'.
> Could not resolve all task dependencies for configuration ':core:scalaCompilerPlugins'.
> Could not resolve io.tryp:splain_2.13.8:1.1.0-SNAPSHOT.
Required by:
project :core
> Could not resolve io.tryp:splain_2.13.8:1.1.0-SNAPSHOT.
> Unable to load Maven meta-data from https://dl.bintray.com/kotlin/kotlin-dev/io/tryp/splain_2.13.8/1.1.0-SNAPSHOT/maven-metadata.xml.
> Could not GET 'https://dl.bintray.com/kotlin/kotlin-dev/io/tryp/splain_2.13.8/1.1.0-SNAPSHOT/maven-metadata.xml'. Received status code 502 from server: Bad Gateway
This is problematic as io.tryp:splain_2.13.8:1.1.0-SNAPSHOT should already be published to maven local, the gradle task sequence log further confirmed this view:
:splain:buildSrc:compileKotlin
:splain:buildSrc:compileJava
:splain:buildSrc:compileGroovy
:splain:buildSrc:pluginDescriptors
:splain:buildSrc:processResources
:splain:buildSrc:classes
:splain:buildSrc:inspectClassesForKotlinIC
:splain:buildSrc:jar
:splain:buildSrc:assemble
:splain:buildSrc:compileTestKotlin
:splain:buildSrc:pluginUnderTestMetadata
:splain:buildSrc:compileTestJava
:splain:buildSrc:compileTestGroovy
:splain:buildSrc:processTestResources
:splain:buildSrc:testClasses
:splain:buildSrc:test
:splain:buildSrc:validatePlugins
:splain:buildSrc:check
:splain:buildSrc:build
(no publishToMavenLocal!)
So I just need to trigger it
According to the Gradle document at https://docs.gradle.org/current/userguide/composite_builds.html#included_build_task_dependencies, the task name you are using is missing the colon :. It should be:
tasks.findByPath(":configuration")?.dependsOn( gradle.includedBuild("splain").task(":publishToMavenLocal"))
Edit: the depending task should be :configuration task
While trying to upgrade some of our scripts to Gradle 4.0.1 on of the plugins we are using is failing and I thought of fixing that plugin first. The plugin is a third party open source project.
So I have cloned the project and tried to compile it. However it fails with following message:
c:\source\gradle-xld-plugin>gradlew build
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\source\gradle-xld-plugin\build.gradle' line: 2
* What went wrong:
Plugin [id: 'com.gradle.plugin-publish', version: '0.9.7'] was not found in
any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- maven(https://artifactory/java-v) (Could not resolve plugin artifact 'com.gradle.plugin-publish:com.gradle.plugin-publish.gradle.plugin:0.9.7')
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --
debug option to get more log output.
BUILD FAILED in 0s
The build.gradle script for the plugin starts like this:
plugins {
id "com.gradle.plugin-publish" version "0.9.7"
id "com.github.hierynomus.license" version "0.11.0"
id 'nebula.nebula-release' version '4.0.1'
id "com.jfrog.bintray" version "1.7.3"
}
In addition to this the company policy dictates we have to go through an internal artifactory server, so following has been added to the settings.gradle file:
pluginManagement {
repositories {
maven {
url "https://artifactory/java-v"
}
}
}
The jar file exists at following location: https://artifactory/java-v/com/gradle/publish/plugin-publish-plugin/0.9.7/plugin-publish-plugin-0.9.7.jar
but when I look at the error message I am a little puzzled that it says that it cannot find com.gradle.plugin-publish:com.gradle.plugin-publish.gradle.plugin:0.9.7.
It seems to have suffixed the id with .gradle.plugin.
Does anyone know whether I am looking at the wrong location or how come it is suffixing the id with .gradle.plugin. And shouldn't it look at a location that has the GAV like this: com.gradle.plugin-publish:com.gradle.plugin-publish:0.9.7?
And does anyone know about how the resolution mechanism for the new plugin mechanism in Gradle works.
Thanks in advance
Edit
Thanks to Mateusz Chrzaszcz I was able to progress.
The only caveat I have with the solution is that it seems like a workaround rather than a solution. But it works!
In addition to his solution you had to resolve the plugins. I was able to hack my way to actually resolve the appropriate names.
In order to do so one has to do as follows:
In a webbrowser go for the plugin: id "com.github.hierynomus.license" version "0.11.0" go to following URL: https://plugins.gradle.org/api/gradle/4.0.1/plugin/use/com.github.hierynomus.license/0.11.0
The json returned contains the GAV needed in the useModule call. Use that
The following serves as an example:
resolutionStrategy {
eachPlugin {
if (requested.id.namespace == 'com.gradle' && requested.id.name == 'plugin-publish') {
useModule('com.gradle.publish:plugin-publish-plugin:0.9.7')
} else if(requested.id.namespace == 'com.github.hierynomus' && requested.id.name == 'license') {
useModule('nl.javadude.gradle.plugins:license-gradle-plugin:0.11.0')
}
}
}
Try to implement Plugin Resolution Rules.
According to gradle documentation:
Plugin resolution rules allow you to modify plugin requests made in plugins {} blocks, e.g. changing the requested version or explicitly specifying the implementation artifact coordinates.
To add resolution rules, use the resolutionStrategy {} inside the pluginManagement {} block
like that:
pluginManagement {
resolutionStrategy {
eachPlugin {
if (requested.id.namespace == 'com.gradle.plugin-publish') {
useModule('com.gradle.plugin-publish:0.9.7') //try a few combinations
}
}
}
repositories {
maven {
url 'https://artifactory/java-v'
}
}
}
Keep in mind this is incubating feature though.
My build.gradle file contains a section like this to upload archives to SonaType:
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment {
MavenDeployment deployment -> signing.signPom(deployment);
}
// HERE
repository(url: sonatypeRepoURI) {
authentication(userName: sonatypeUsername,
password: sonatypePassword);
}
pom.project {
// etc etc
}
}
}
}
At the point marked HERE, other users wishing to use my build file will fail, because at least the first variable is not defined:
FAILURE: Build failed with an exception.
* Where:
Build file '/path/to/build.gradle' line: 144
* What went wrong:
A problem occurred evaluating root project 'whateverTheProject'.
> No such property: sonatypeRepoURI for class:
org.gradle.api.publication.maven.internal.ant.DefaultGroovyMavenDeployer
How do I modify the section above so that users are not affected by these variables not being defined for them?
You could try to add all the needed properties to your gradle.properties file, which you add to version control, but leave the values empty.
Eg:
version=1.0
signing.keyId=
signing.password=
signing.secretKeyRingFile=
sonatypeUsername=
sonatypePassword=
Then you override these in your own ${USER}/.gradle/gradle.properties.
As an example take a look at a working project https://github.com/judoole/monitorino. Should be able to run all tasks at any machine except snapshot, stage and build.
Edit: I would not do it like this today. Follow the Gradle guide, using required. Just as the example from #jb-nizet Gradle ref 53.3.3 Conditional Signing: http://www.gradle.org/docs/current/userguide/signing_plugin.html
Very simple just create the "gradle.properties" file in "~/.gradle" with the following contents:
sonatypeUsername=
sonatypePassword=
After run your project. Its running properly.
I am trying out the new Sonar Runner task recently released in gradle 1.5. What I would like to do is be able to make the sonar runner task dependent on another task so that I can set the Sonar properties correctly for this project (i.e. sonar.sources, sonar.binaries, sonar.libraries, sonar.java.source, sonar.java.target).
Specifically I am using an osgi build tool called bnd which will provide these values when an ant init task is executed (note that whilst I include the default bnd build.xml file, my complete build is really being done using gradle).
I thought I would be able to customize the sonar runner task by doing this (this is a multi-module build):
subprojects {
sonarRunner.dependsOn init
}
Eventually adding something like this (from what I understand of the bnd ant variables):
subprojects {
sonarRunner {
sonarProperties {
property "sonar.java.source", ant.property["project.sourcepath"]
property "sonar.java.target", ant.property["project.output"]
property "sonar.sources", ant.property["project.allsourcepath"]
property "sonar.libraries", ant.property["project.buildpath"]
}
}
sonarRunner.dependsOn init
}
Unfortunately when I try to add the dependsOn I get the error:
* What went wrong:
A problem occurred evaluating root project 'myproject'.
> Could not find property 'init' on project ':com.company.myproject.mymodule'.
If I try to make sonarRunner depend on a gradle task I get the following error:
* What went wrong:
A problem occurred evaluating root project 'myproject'.
> Could not find method dependsOn() for arguments [task ':gradletask'] on org.gradle.api.sonar.runner.SonarRunnerExtension_Decorated#c4d7c0c.
Am I missing something obvious here? If someone could point me in the right direction it would be a big help.
Your problem with not being able to call dependsOn() on sonarRunner task comes from the fact that the plugin defines both both sonarRunner extension and a sonarRunner task. It looks like extensions take precedence over tasks when objects are resolved by name in a gradle build file, hence your stacktrace points out that you are trying to call dependsOn() on an instance of org.gradle.api.sonar.runner.SonarRunnerExtension_Decorated instead of caling it on a SonarRunner task instance.
I think that if you retrieved the task from the task container explicitly you should be ok:
tasks.sonarRunner.dependsOn init
The root project gradle file is evaluated before the child project gradle files, that means init does not exist on the location you try to address it.
A workaround if you want to declare dependencies in the root project is to use afterEvaluate as described in http://www.gradle.org/docs/current/userguide/build_lifecycle.html, try:
subprojects {
afterEvaluate{
sonarRunner.dependsOn init
}
}
Another solution would be to add the dependency in the sub projects, directly or by applying another root gradle file.
apply from: '../sonardependency.gradle'
If anyone is interested, this is one way of getting the bnd information to be set correctly in Sonar for each subproject (I am sure there are better ways):
subprojects {
afterEvaluate {
sonarRunner {
sonarProperties {
ant.taskdef(resource:"aQute/bnd/ant/taskdef.properties",
classpath: "../cnf/plugins/biz.aQute.bnd/biz.aQute.bnd-2.0.0.jar");
def projectDir = project.rootDir.toString() + "/" + project.name;
ant.bndprepare(basedir:projectDir,print:"false",top:null);
def binaries = ant.properties['project.buildpath'].split(':') as ArrayList;
binaries.remove(0);
def binariesString = binaries.join(',');
properties["sonar.java.source"] = ant.properties['javac.source'];
properties["sonar.java.target"] = ant.properties['javac.target'];
properties["sonar.binaries"] = ant.properties['project.output'].replace(':',',');
properties["sonar.sources"] = ant.properties['project.sourcepath'].replace(':',',');
properties["sonar.libraries"] = binariesString;
}
}
}
}