how to install missing jenkins plugins, when using gradlew? - java

When I try to run
gradlew 'task'
I get this following error message:
(I am obviously missing some jenkins plugins)
* What went wrong:
Error resolving plugin [id: 'com.terrafolio.jenkins', version: '1.3.2'].
> Could not resolve all dependencies for configuration 'detachedConfiguration1'.
> Could not find org.jenkins-ci.plugins:job-dsl-core:1.42.
Searched in the following locations:
https://plugins.gradle.org/m2/org/jenkins-ci/plugins/job-dsl-
core/1.42/job-dsl-core-1.42.pom
https://plugins.gradle.org/m2/org/jenkins-ci/plugins/job-dsl-
core/1.42/job-dsl-core-1.42.jar
Required by:
unspecified:unspecified:unspecified > com.terrafolio:gradle-jenkins-plugin:1.3.2
My task looks like this: (running a groovy script)
task testDeployOsb << {
javaexec {
classpath = configurations.osb
main = 'groovy.ui.GroovyMain'
args = ["support-scripts/deployAlsb.groovy",
"${buildDir}/deployment.groovy"]
jvmArgs = ["-Dweblogic.MaxMessageSize=200000000",
"-Dweblogic.CompleteT3MessageTimeout=480",
"-Dweblogic.CompleteMessageTimeout=480",
"-Dweblogic.wsee.transport.read.timeout=600000",
"-Dweblogic.wsee.transport.connection.timeout=600000"]
}
}
So how do I install said plugins?

You will have define at least one repository that can serve the external plugin. Maven Central seems to have it. Also the Gradle plugin portal hosts the plugin. You can find the notation for including it here.

Related

Gradle Spring Cloud Stream project does not build because of test dependency

When I try to build a Gradle Spring Boot project with Spring Cloud Stream I receive the following error:
Execution failed for task ':compileTestJava'.
> Could not resolve all files for configuration ':testCompileClasspath'.
> Could not find org.springframework.cloud:spring-cloud-stream:test-binder.
Required by:
project :
> Could not find org.springframework.cloud:spring-cloud-stream:test-binder.
Required by:
project :
> Could not find org.springframework.cloud:spring-cloud-stream:test-binder.
Required by:
project : > org.springframework.cloud:spring-cloud-stream-binder-kafka-streams:3.0.9.RELEASE > org.springframework.cloud:spring-cloud-stream-binder-kafka-core:3.0.9.RELEASE
The project works fine if I remove the following dependency:
testImplementation 'org.springframework.cloud:spring-cloud-stream:test-binder#test-jar'
The project was generated using Spring initilizr with this configuration.
What can I change so the project builds successfully?
Change
testImplementation 'org.springframework.cloud:spring-cloud-stream:test-binder#test-jar'
to
testImplementation("org.springframework.cloud:spring-cloud-stream") {
artifact {
name = "spring-cloud-stream"
extension = "jar"
type ="test-jar"
classifier = "test-binder"
}
}
Currently, Spring Initializr generates Gradle projects with this error and the problem is documented in #1159 and
#591.

How to get the next build number in Gradle

Is there any way to get the next version when publishing to a repository in gradle?
For e.g. if I have the version 3.0.1 in my repository I want the published version to be 3.0.2.
ivy has a task for ant named buildnumber which does exactly that:
<project xmlns:ivy="antlib:org.apache.ivy.ant"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<target name="ivyBuildNumber" description="Use ivy get the next build number">
<ivy:buildnumber
resolver="url-chain"
organisation="${ivy.organisation}"
module="${ivy.module}"
revision="${version.base}"/>
<echoproperties prefix="ivy.new."/>
</target>
Is there a way to do so in gradle? if not how can I access ivy tasks from gradle's ant?
In my build.gradle I calling to the ant
ant.importBuild 'build.xml'
I don't think there is support in Gradle, but you can try to use the Ant task.
https://docs.gradle.org/current/userguide/ant.html#sec:import_ant_build
Another way to do this is to use some sort of plugin, or customized task for managing the version.
Plugin: https://github.com/researchgate/gradle-release
Custom task: https://www.tikalk.com/devops/increment-version-numbers-in-gradle/
Yes, you can access ivy tasks from the ant script by importing ant's build.xml file to gradle's build.gradle file. Following is the syntax to do so.
ant.importBuild 'build.xml'
Please refer : https://docs.gradle.org/current/userguide/ant.html#sec:import_ant_build
I recommend you to use ResearchGate release plugin
https://github.com/researchgate/gradle-release
It has a pretty documentation. Easy to read.
Also, check out how I used it in my personal project.
https://github.com/vatolinrp/bitcoin-esb/blob/master/build.gradle
It would be a nice example for you.
After a long work, I managed to do that.
In my build.gradle I added this following code
ant.importBuild 'build.xml'
task getNextBuild(dependsOn : ivyBuildNumber) {
doLast{
def nextVersion = ant.properties['ivy.new.revision']
println nextVersion
}
}
I imported my ant build file, and created a task that calls the ivy buildnumber task.
There is my build.xml
<project xmlns:ivy="antlib:org.apache.ivy.ant">
<target name="ivyBuildNumber">
<path id="ivy.classpath" path="lib/ivy.jar" />
<typedef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpathref="ivy.classpath" />
<ivy:buildnumber
organisation="daniel"
module="hello"/>
<echoproperties prefix="ivy.new."/>
</target>
</project>
Because my IDE (Intellij), didn't have ivy.jar in the content,
I imported the ivy.jar from my root dir (lib/ivy.jar)
For this exact behavior, Ivy buildnumber task can be invoked using pure Gradle without importing the Ant build:
configurations {
antTasks // define a new configuration
}
repositories {
mavenCentral()
}
dependencies {
antTasks("org.apache.ivy:ivy:2.4.0") // add Ivy library to it
}
ext {
// define the Ivy task, using the extra configuration as classpath extension
ant.taskdef(name: "ivyBuildNumber",
classname: "org.apache.ivy.ant.IvyBuildNumber",
classpath: configurations.antTasks.asPath)
ant.ivyBuildNumber(organisation: "daniel", module: "hello")
nextVersion = ant.properties["ivy.new.revision"]
}
task demo {
doLast {
println nextVersion
}
}
In general, Gradle doesn't have any bundled equivalent to Maven Release Plugin, so one has to rely on plugins. One solid plugin is gradle-release by ResearchGate, the other is axion by Allegro Tech. The former is classic Maven-style versioning, the latter takes SCM itself as the only source of truth, eliminating the versioning in the build files. But neither of these plugins does provide the exact requested behavior.
My personal take on the versioning problem was initially to use some plugins. Since I use Bamboo as CI server at work, literally everything I did with release plugins using Gradle crashed on CI server sooner or later. It might have worked for some weeks, but every server update brought some problems. I ended up using SCM-less approach with a simple convention: use branch name as base version, concatenate it with build number (both values are provided by the CI server):
ext {
branch = System.getProperty("branch", "develop")
buildNumber = System.getProperty("buildNumber", "latest")
isRelease = System.getProperty("isRelease", "false").toBoolean()
artifactVersion = "${branch}${(isRelease ? ".$buildNumber" : "-SNAPSHOT")}"
}
CI server then can be set up for executing the following command
./gradlew -DisRelease=true -Dbranch=${git.branch} -DbuildNumber=${build.number} mavenPublish
when 'Release' button is pushed. For example, build 12 of the 3.0 branch will produce version 3.0.12 in the binary repository.
The advantages are:
+ the version comes for free, assuming the branches are named accordingly
+ the auto-incremented build number also comes for free
+ one can easily publish custom revisions
+ no plugins means no problems with Gradle version updates
+ this approach is dead simple and always works
The downsides are:
- additional script tasks are required for tags
- some build numbers will be skipped, obviously (e.g. next version after 3.5.76 can be 3.5.84)

How to feed Antlr goal from local maven repository?

I am trying to build my project on an offline machine (this is a requirement). I have created local maven repository (it's just a folder with appropriate structure) and successfully build all other things.
I do the following way:
1) Run gradle installl (this maven plugin's goal)
then checking errors by hand. If I see some library not found, then
2) I take it's maven coordinates and copy in to this machine by hand from my machine.
It works except of Antlr. I getting the following message:
>gradle install
:generateGrammarSource
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all dependencies for configuration ':antlr'.
> Could not download antlr4.jar (org.antlr:antlr4:4.5)
> Could not get resource 'http://repo.maven.apache.org/maven2/org/antlr/antlr4/4.5/antlr4-4.5.jar'
> Could not HEAD 'http://repo.maven.apache.org/maven2/org/antlr/antlr4/4.5/antlr4-4.5.jar'.
> Connection to http://repo.maven.apache.org refused
error message is the same as always, but this time putting jar into local maven repository does not help.
How to overcome? How to configure Antlr to eat from local maven repo?
UPDATE
File is present in
MYHOME\.gradle\caches\modules-2\files-2.1\org.antlr\antlr4\4.5\af4a530e3cd7fa03636645d8077145eefac12907\antlr4-4.5.jar
and in
MYHOME\.m2\repository\org\antlr\antlr4\4.5\antlr4-4.5.jar
In maven case accompaning files are also present.
UPDATE 2
Note that it says
Could not resolve all dependencies for configuration ':antlr'.
and Antlr dependency is added by
antlr "org.antlr:antlr4:4.5" // use ANTLR version 4
i.e. not compile and not testCompile. May be this is the clue? May be it is a way to configure repositores specifically to antlr configuration?
UPDATE 3
I those cases I was resolving successfully it was writing:
Could not resolve all dependencies for configuration ':compile'.
> Could not resolve net.coobird:thumbnailator:0.4.8.
Required by:
com.cireca.overlaywidget:OverlayWidget:1.0-SNAPSHOT
> Could not resolve net.coobird:thumbnailator:0.4.8.
> Could not get resource 'https://repo1.maven.org/maven2/net/coobird/thumbnailator/0.4.8/thumbnailator-0.4.8.pom'.
> Could not GET 'https://repo1.maven.org/maven2/net/coobird/thumbnailator/0.4.8/thumbnailator-0.4.8.pom'.
> Connection to https://repo1.maven.org refused
UPDATE 4
Strange thing. I noticed that my config looks redundant:
repositories {
maven { url "http://repo.maven.apache.org/maven2" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "http://maven-eclipse.github.io/maven" }
mavenLocal()
flatDir {
dirs 'lib'
}
maven { url "http://repo.maven.apache.org/maven2" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "http://maven-eclipse.github.io/maven" }
}
I changed this to
repositories {
mavenLocal()
flatDir {
dirs 'lib'
}
maven { url "http://repo.maven.apache.org/maven2" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "http://maven-eclipse.github.io/maven" }
}
And after that it started to claim different liraries. First it claimed
org.antlr:antlr4-runtime:4.5
and I fed it successfully, but then it claimed
org.antlr:antlr-runtime:3.5.2
and I can't feed it (same situation).
Maven contacts the repositories as specified in your settings.xml. If you want to avoid external repositories, you need to mirror everything.
Actually, the best approach to work in environment not connected to the internet is to set up your own Nexus/Artifactory. And the easiest way to fill up your repository for offline use to connect it to the internet once, then build everything and disconnect. Then you have a local copy of everything that is relevant for you.
I have removed remote repositories references completely from that machine (before this the remote repositories just had lower priority).
After that the Gradle started to report what it miss in the form of explicit local paths and I found, that it had lack of some parent (?) artifacts.
For example, for Guava, it was wishing com.google.guava:guava-parent and for antlr it was org.antlr:antlr-master. These names were not reported when remote repositories were present in the config.
If anybody could explain what happened in more detailed way, I will accept his/her answer.

Migration from maven to gradle

We are migrating maven project to gradle. We have flex for front end and as requested we are migrating it as well using gradlefx. Have added the dependencies:
dependencies{
classpath 'com.adobe.flex.framework:flex-framework:4.0.0.14159'
classpath files("./libs/flex/parsley-core-3.0.0.swc")
classpath files("./libs/flex/parsley-flex-3.0.0.swc")
classpath files("./libs/flex/legacy-parsley-commands-2.5.0.swc")
classpath files("./libs/flex/spicelib-commands-3.1.1.swc")
classpath files("./libs/flex/spicelib-reflect-3.0.0.swc")
classpath files("./libs/flex/spicelib-util-3.1.0.swc")
}
2.My mxml has contents like:
<?xml version="1.0" encoding="utf-8"?>
<Object xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns="http://www.spicefactory.org/parsley">
<fx:Script><![CDATA[//some imports]]></fx:Script></Object>
However on build am getting following error.
[ant:java] Java Result: 1
FAILED
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task :Common_Components:compileFlex.
java.lang.Exception: mxmlc execution failed: Loading configurationfile D:\Softwares\flex_sdk_4.6\frameworks\flex-config.xmlD:\Xyz\Workspace\Common_Components\src\com\abc\common\MenuContext.mxml(9): Error: Could not resolve to a component implementation. xmlns:presentation1="com.abc.helpframework.presentation.*">`
The same setup is working for other mxml file. I doubt with object tag, not very sure though.

Unable to Run Grails, error with resolving class

I am fairly new to grails and need help figuring out why I cannot run grails due to this error below:
grails> run-app
| Running application...
startup failed:
C:\DIR\grails-inventory\grails-app\controllers\harbor\AssetController.groovy: 3: unable to resolve class org.apache.jasper.compiler.Node.ParamsAction
# line 3, column 1.
import org.apache.jasper.compiler.Node.ParamsAction;
^
1 error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileGroovy'.
> Compilation failed; see the compiler error output for details.
If I were to comment out that particular line in AssetController, grails will execute however the whole application will have NullPointer errors
Try to add this to Gradle dependencies:
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g.
// runtime 'mysql:mysql-connector-java:5.1.22'
compile 'tomcat:jasper-compiler:5.5.9'
}
You can find jasper for Grails 2.x:https://grails.org/plugin/jasper and plugins for Grails 3.x are here: https://bintray.com/grails/plugins, but as I see there is no Jasper plugin for Grails 3, so try to add dependency directly as mentioned above.

Categories