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

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.

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

Plugins in a Multiproject fails at Grails 3.2.11

Configuration
Following the Plugins and Multi-Project Builds section at the Grails 3.2.11 manual, its suppose that I can setup a Multi-project with the next commands in a terminal:
echo "Creating the root folder..."
mkdir test-multi-project
cd test-multi-project
echo "Creating the settings.gradle file..."
echo "include 'myapp', 'myplugin'" >> settings.gradle
echo "Creating the Grails application..."
grails create-app myapp
echo "Creating the Grails plugin..."
grails create-plugin myplugin
echo "Configuring the dependency between the application and the plugin..."
echo "grails { plugins { compile project(':myplugin') } }" >> myapp/build.gradle
echo "Executing the Grails application..."
cd myapp
grails run-app
Error
However, when I tried those commands for create and configure the Grails Application and the Plugin the grails run-app command throws next error:
FAILURE: Build failed with an exception.
* Where:
Build file '~/test-multi-project/myapp/build.gradle' line: 61
* What went wrong:
A problem occurred evaluating root project 'myapp'.
> Project with path ':myplugin' could not be found in root project 'myapp'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
CONFIGURE FAILED
Total time: 4.835 secs
| Error Error initializing classpath: Project with path ':myplugin' could not be found in root project 'myapp'. (Use --stacktrace to see the full trace)
Additional Information
I already tested the above commands using Grails 3.2.8, 3.2.9, 3.2.10 and 3.2.11 and the code throws the same error.
On the other hand, I tested the above commands using Grails 3.2.3, 3.2.5, and 3.2.7 and the project is executed fine. Also, the Grails landing page shows that 'mypluin' is been used by the application.
Note, I am using sdk to handle the Grails versions. The commands were executed using Java 1.7 and Yosemite:
Groovy: 2.4.7
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.7.0_141 (Azul Systems, Inc. 24.141-b11)
OS: Mac OS X 10.10.5 x86_64
Question:
I am wondering what else I need to do or what I am doing wrong in order to make this code works on Grails 3.2.11
Thanks in advance.
Jeff Brown fixed the above issue removing the multi-project-test2/myapp/settings.gradle file and adding the next line to the multi-project-test2/settings.gradle file:
project(':myapp').name = 'myapp'
As you can see at the next GitHub's commit: https://github.com/esalomon/multi-project-test2/commit/d92c3fbc67156bcd1af9f47dc6f2984534154bad
After the above updated the multi-project-test2 can be downloaded and it will work fine.
It is likely to have gone wrong at around this point:
echo "grails { plugins { compile project(':myplugin') } }" >> myapp/build.gradle
That segment needs to be added to existing block of that file not a new block (not that I have tested)
What happens when you follow the steps manually ? does it work that way and if so have you thought of doing a diff across files that changes to see what is different.
You are providing the script which is great and maybe someone else wishes to run through it but i suspect it is what has already been pointed out.
You should look into ed Something like this example:
I am using a grails 3.2.8 app which in the dependency segment ends like this:
runtime "com.h2database:h2"
testCompile "org.grails:grails-plugin-testing"
testCompile "org.grails.plugins:geb"
testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
Now if I execute
test328$ ed -s build.gradle <<EOF >/dev/null
g/^ testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
a
compile project(':myplugin')
.
w
q
EOF
you can now see:
tail -n20 build.gradle
runtime "com.h2database:h2"
testCompile "org.grails:grails-plugin-testing"
testCompile "org.grails.plugins:geb"
testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
compile project(':myplugin')
}
The new entry added on. You will need to find a pointer in your existing file generated by grails and use like above that pointer to add your entry
The ed script was used to demo this since obviously it wasn't clear enough previously

Custom Ant Task Not Working On Build Server

I've got a custom Ant task that I'm using successfully from gradle on my local machine:
task fetchRelMod {
doLast {
println 'Fetching the RelMod'
ant.taskdef(name:'relmod',
classpath:'retrievePBSInfo.jar:hsjt400-4-9.jar',
classname:"com.myco.ant.tasks.RetrievePBSRelModString")
ant.relmod(user:project.ext.props.getProperty('fetchrelmod.username'),
password:project.ext.props.getProperty('fetchrelmod.password'),
prodCode:project.ext.props.getProperty('profile.pbs.product.code'),
branch:project.ext.props.getProperty('profile.pbs.branch'),
state:project.ext.props.getProperty('profile.pbs.relmod.selector'))
project.ext.set('iseries_relmod',ant.relmodStub)
project.ext.set('iseries_relmodAndDate', ant.relmod)
}
}
I've got the jar files sitting next to build.gradle for now, out of simplicity... they exist in the same location on the build server. Works great locally. When I run my build from my build server (either through Jenkins or going on the box and running Gradle directly), I get the following:
sudo /var/lib/jenkins/tools/hudson.plugins.gradle.GradleInstallation/gradle214/bin/gradle all -DisQUABuild=true
Building My App
Loading Properties files...
QUA Build. Using build-qua.props
:fetchRelMod
Fetching the RelMod
:fetchRelMod FAILED
FAILURE: Build failed with an exception.
* Where:
Build file '/var/lib/jenkins/workspace/MyApp/build.gradle' line: 141
* What went wrong:
Execution failed for task ':fetchRelMod'.
> taskdef class com.myco.ant.tasks.RetrievePBSRelModString cannot be found
using the classloader AntClassLoader[/var/lib/jenkins/workspace/myApp/hsjt400-4-9.jar]
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 3.104 secs
What concerns me is that there are two jar files in the classpath and it only mentions one in the error. Does anyone have any ideas as to what might be going on?

Grails: Cobertura XML report missing on Sonar

I'm working on a web application using Grails 2.1.1 and it was requested me to make evidence about the test code coverage.
The project is using:
Maven 3.0.5
code-coverage 1.2.7 (grails plugin for Cobertura)
sonar-maven-plugin 2.5
SonarQube 3.7.4 (running on localhost)
On my pom.xml, there are declared the following sonar's properties:
<sonar.language>grvy</sonar.language>
<sonar.groovy.cobertura.reportPath>target/test-reports/cobertura/coverage.xml</sonar.groovy.cobertura.reportPath>
I successfully generate cobertura.xml report inside directory target/test-reports/cobertura, launching the command:
grails tA -coverage -xml
but when I run:
mvn sonar:sonar
It isn't displayed any test report on Sonar, although I receive as command response the following output lines:
[INFO] [15:20:42.007] Sensor Groovy CoberturaSensor...
[INFO] [15:20:42.007] Analyzing Cobertura report: target/test-reports/cobertura/coverage.xml
[INFO] [15:20:42.086] Sensor Groovy CoberturaSensor done: 79 ms

Issue with gradle job in jenkins with JDK 1.8

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

Resources