Issue with gradle job in jenkins with JDK 1.8 - jenkins

I am able to run gradlew test clean in the command prompt where Jenkins is running. When I use Gradle Wrapper and run clean test in Jenkins, the job is failing with:
Execution failed for task ':compileJava'.
> invalid source release: 1.8
My wrapper is using gradleVersion = 1.10 and the gradlew -v shows the following:
C:\Program Files (x86)\Jenkins\jobs\CDS-UnitTest\workspace>gradlew -v
------------------------------------------------------------
Gradle 1.10
------------------------------------------------------------
Build time: 2013-12-17 09:28:15 UTC
Build number: none
Revision: 36ced393628875ff15575fa03d16c1349ffe8bb6
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.9.2 compiled on July 8 2013
Ivy: 2.2.0
JVM: 1.8.0_05 (Oracle Corporation 25.5-b02)
OS: Windows Server 2012 R2 6.3 amd64
I'm not able to figure out why it is failing in Jenkins for JDK 1.8 while it works in the command line.
Jenkins console:
[workspace] $ cmd.exe /C '""C:\Program Files (x86)\Jenkins\jobs\CDS-UnitTest\workspace\gradlew.bat" -DSOURCE_BUILD_NUMBER=14 clean test && exit %%ERRORLEVEL%%"'
...
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> invalid source release: 1.8

Related

Gradle with Java11 build produces intermittent compilation errors

We are using gradle:6.9.1-jdk11-hotspot image to build one of our java jar components.
Gradle 6.9.1
Build time: 2021-08-20 11:15:18 UTC.
Revision: f0ddb54aaae0e44f0a7209c3c0274d506ea742a0
Kotlin: 1.4.20
Groovy: 2.5.12
Ant: Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM: 11.0.11 (AdoptOpenJDK 11.0.11+9)
OS: Linux 5.10.47-linuxkit amd64.
The Gradle build file also use io.freefair.aspectj.compile-time-weaving:3.8.4 for compile time weaving.
We get the following compilation errors
The type javax.xml.stream.XMLEventReader is not accessible.
import javax.xml.stream.XMLEventReader;
The type javax.xml.stream.XMLInputFactory is not accessible
import javax.xml.stream.XMLInputFactory;
XMLEventReader cannot be resolved to a type
private XMLEventReader xmlEventReader;
XMLInputFactory cannot be resolved
XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
This compilation error does not happen consistently and it happens intermittently. Retrying after a couple of times the build succeeds.
We use docker-compose of version 2.0.1 to build the image. The Gradle build is executed as part of building the docker image.
Here is the Dockerfile:
FROM gradle:6.9.1-jdk11-hotspot
ENV GRADLE_USER_HOME=/app/.gradle
USER root
WORKDIR app/libs
COPY common/*.gradle ./common/
COPY common/src ./common/src
RUN gradle --stacktrace --no-daemon :common:build

Error cleanup script CloudBees Jenkins unable to resolve class com.cloudbees.hudson.plugins.folder.AbstractFolder

My question is about a groovy script that fails.
I tried to run it from a freestyle job with a Build Step "Execute system Groovy script" and 'Groovy command' where I have pasted the script from this source and I also tried running the scripts directly from the script console.
(Another script I tried which gives a different error: this one)
I found this article already here and some other ones, but it hasn't helped me out so far so I would like to run it by the community here.
I understand that there's likely more to it than described here, but I have hope.
I am admin of a couple of old (v1.580.13) Cloudbees Jenkins servers I need to support and can't yet decommission and I used to run a cleanup script which clears out workspaces on slaves.
Environment (masters and agents)
OLD = RHEL 6.x physical - there the script worked
NEW = CentOS 7.x VM - here it doesn't
For some reason that is beyond me it is not working on my new environment and produces an error that refers to the Folders plugin which I don't understand since the plugin is installed and was not changed as far as I know.
Both "Folders Plugin" (4.7) and "CloudBees Folders Plus Plugin" (2.10) are installed and I can see the related files in:
$JENKINS_HOME/plugins/cloudbees-folder
$JENKINS_HOME/plugins/cloudbees-folder.jpi
../cache/war/WEB-INF/plugins/cloudbees-folder.hpi
Groovy plugin v1.14 is also installed as is Groovy runtime (Groovy Version: 1.8.9 JVM: 1.8.0_191 Vendor: Oracle Corporation as OS package as well as having 'Groovy installations' in Jenkins configuration: Groovy 2.5.4 & 2.1.9 from http://groovy.codehaus.org - install automatically) for master and agents.
The exact error output in the console is:
FATAL: startup failed:
Script1.groovy: 19: unable to resolve class com.cloudbees.hudson.plugins.folder.AbstractFolder
# line 19, column 24.
if(item instanceof com.cloudbees.hudson.plugins.folder.AbstractFolder) {
^
1 error
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 19: unable to resolve class com.cloudbees.hudson.plugins.folder.AbstractFolder
# line 19, column 24.
if(item instanceof com.cloudbees.hudson.plugins.folder.AbstractFolder) {
^
1 error
at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:302)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:861)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:550)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:499)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:302)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:281)
at groovy.lang.GroovyShell.parseClass(GroovyShell.java:731)
at groovy.lang.GroovyShell.parse(GroovyShell.java:743)
at groovy.lang.GroovyShell.parse(GroovyShell.java:723)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:680)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:666)
at hudson.plugins.groovy.SystemGroovy.perform(SystemGroovy.java:81)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:770)
at hudson.model.Build$BuildExecution.build(Build.java:199)
at hudson.model.Build$BuildExecution.doRun(Build.java:160)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:533)
at hudson.model.Run.execute(Run.java:1745)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:89)
at hudson.model.Executor.run(Executor.java:240)
Help is greatly appreciated!

ant build failes on Jenkins

When I start the Jenkins build, on arriving on ant-build-step the build is canceled immediately with the following stack:
...
[PROJECT] $ cmd.exe /C "D:\jenkins\tools\hudson.tasks.Ant_AntInstallation\Ant\bin\ant.bat -file build-jenkins.xml -Djenkins.result.dir=${JENKINS.WORKSPACES}/Results "-Dbranch=*/develop" -Djenkins.result.dir=C:/Tools/Jenkins/Results -Djenkins.workspace.dir=C:\Tools\Jenkins\Project-SNAPSHOT\workspace/PRO_56/PRO/java/Project -Dproject.path=C:\Tools\Jenkins\Project-SNAPSHOT\workspace clean.compile.jar.server.snapshot -v && exit %%ERRORLEVEL%%"
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
...
See http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details.
Build step 'Invoke Ant' marked build as failure
Finished: FAILURE
I get no debug messages, nothing.
I've got other project with a similar/equal config which work. I think it could be a incompatibility of my plugins.
Has anyone experienced this bug before?
In my case the problem was a big M in the java options of the ant-build-step.
Here no m for Megabit und M für Megabyte.
-Xmx1024M
-Xms1024m

Can't build basic rest-api project in Grails 3.1.0

I've just created a test project in Grails 3.1.0 that uses the new rest-api profile:
grails create-app rest-test --profile=rest-api
Without any modifications, when I try and gradle build the application the build fails:
cd rest-test
gradle build
:compileJava UP-TO-DATE
:compileGroovy
:processResources
:classes
:compileTestJava UP-TO-DATE
:compileTestGroovy UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:compileIntegrationTestJava UP-TO-DATE
:compileIntegrationTestGroovy UP-TO-DATE
:findMainClass
:buildProperties
:compileGsonViews
Invalid arguments: [C:\projects\rest-test\grails-app\views,C:\projects\rest-test\build\gson-classes\main,1.8,rest-test,C:\projects\rest-test\grails-app\conf\application.yml,UTF-8]
Usage: java -cp CLASSPATH grails.plugin.json.view.JsonViewCompiler [srcDir] [destDir] [targetCompatibility] [packageImports] [packageName] [configFile] [encoding]
:compileGsonViews FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileGsonViews'.
> Process 'command 'C:\Program Files\Java\jdk1.8.0_66\bin\java.exe'' finished with non-zero exit value 1
Looking at that error message, it seems there aren't enough arguments passed to the java call.
If I do a grails run-app I'm able to start the app successfully and can see the gson views at localhost:8080.
Does anyone have any ideas why the gradle build command is failing?
Found the solution on Grails GitHub issue tracker:
Please replace the line
classpath "org.grails.plugins:views-gradle:1.0.1"
With
classpath "org.grails.plugins:views-gradle:1.0.3"
In your build.gradle file
I tested it with Grails 3.1.2 -- it works!

Gradle : How to define a task that depend on an ant target

Hi if i list all tasks with gradle testGradle tasks -- all I see all imported ant tasks, but when i try to create my task that depends on an ant task, I am getting "Could not determine the dependencies of task ':testGradle'.
the line that is a problem: task testGradle(dependsOn: 'init' ) - it clearly doesn't see ant init task.
What did I do wrong?
build.gradle
println "this will always runs first"
task buildM << {
println "Importing ..."
ant.importBuild 'build.xml'
println "Done importing"
}
task testGradle(dependsOn : init ) << {
println tasks.getByPath('init').path
}
gradle tasks all
Other tasks
all
compile - Compile main source tree java files
deploy - deploy WAR file
**init** - Prepare for running compiling artifacts
....
byWorld5
copyTestConfiguration - Copy unit test configurations
deployLoggerProperties - Deploy logging.properties to tomcat
execMoped
importTasks
install - Install application in Tomcat
list - List Tomcat applications
init - Prepare for running compiling artifacts
reload - Reload application in Tomcat
start - Start Tomcat application
stop - Stop Tomcat application
test - Run junit tests
compile - Compile main source tree java files
init - Prepare for running compiling artifacts
> gradle -v
Gradle 1.1
Gradle build time: Tuesday, July 31, 2012 1:24:32 PM UTC
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.8.4 compiled on May 22 2012
Ivy: 2.2.0
JVM: 1.6.0_24 (Sun Microsystems Inc. 20.0-b12)
OS: Linux 2.6.32-220.23.1.el6.x86_64 amd64
>gradle -c
org.gradle.api.GradleScriptException: A problem occurred evaluating root project 'moped_gradle'.
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:54)
at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:127)
at org.gradle.configuration.BuildScriptProcessor.evaluate(BuildScriptProcessor.java:38)
at org.gradle.configuration.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:43)
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:463)
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:75)
at org.gradle.configuration.ProjectEvaluationConfigurer.execute(ProjectEvaluationConfigurer.java:23)
at org.gradle.configuration.ProjectEvaluationConfigurer.execute(ProjectEvaluationConfigurer.java:21)
at org.gradle.configuration.DefaultBuildConfigurer$1.execute(DefaultBuildConfigurer.java:38)
at org.gradle.configuration.DefaultBuildConfigurer$1.execute(DefaultBuildConfigurer.java:35)
at org.gradle.api.internal.project.AbstractProject.configure(AbstractProject.java:439)
at org.gradle.api.internal.project.AbstractProject.allprojects(AbstractProject.java:434)
at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:35)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:139)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:110)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:78)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:38)
at org.gradle.launcher.exec.InProcessGradleLauncherActionExecuter.execute(InProcessGradleLauncherActionExecuter.java:39)
at org.gradle.launcher.exec.InProcessGradleLauncherActionExecuter.execute(InProcessGradleLauncherActionExecuter.java:25)
at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
at org.gradle.launcher.cli.ActionAdapter.execute(ActionAdapter.java:30)
at org.gradle.launcher.cli.ActionAdapter.execute(ActionAdapter.java:22)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:200)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:173)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:138)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
at org.gradle.launcher.Main.doAction(Main.java:48)
at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
at org.gradle.launcher.Main.main(Main.java:39)
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)
at org.gradle.launcher.GradleMain.main(GradleMain.java:26)
Caused by: groovy.lang.MissingPropertyException: Could not find property 'init' on root project 'moped_gradle'.
at org.gradle.api.internal.AbstractDynamicObject.propertyMissingException(AbstractDynamicObject.java:43)
at org.gradle.api.internal.AbstractDynamicObject.getProperty(AbstractDynamicObject.java:35)
at org.gradle.api.internal.CompositeDynamicObject.getProperty(CompositeDynamicObject.java:60)
at org.gradle.groovy.scripts.BasicScript.propertyMissing(BasicScript.java:70)
at build_62g86rvs7k0vqsu3ssgdsrobsc.run(/home/natalik/MyInstalls/moped_gradle/build.gradle:14)
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:52)
... 33 more
The ant.importBuild statement must be called during configuration phase to work.
I did it during execution.

Resources