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
Related
I have a dotnet image that is used as an agent for the Jenkins pipeline. Now I want to include sonar scanner in the image so that I can run an analysis and see if the coverage is good. If the coverage is not good then the build should fail. How to include the sonar scanner in my image.
I tried including the skilldlabs/sonar-scanner in my Dockerfile of the dotnet image. but when I run the container it directly executed the sonar cube commands and failed as the default sonarqube address is used.
Below is my current Dockerfile
FROM microsoft/dotnet:2.1-sdk
FROM skilldlabs/sonar-scanner:3.3
COPY some-ca.crt /usr/local/share/ca-certificates
COPY NuGet.Config /build/.nuget/NuGet/
VOLUME [ "/build/sources" ]
WORKDIR /build/sources
When I ran :
docker run --name sonar -it sonar
INFO: Scanner configuration file: /root/sonar-scanner-3.3.0.1492-linux/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarQube Scanner 3.3.0.1492
INFO: Java 1.8.0_191 Oracle Corporation (64-bit)
INFO: Linux 4.9.125-linuxkit amd64
INFO: User cache: /root/.sonar/cache
ERROR: SonarQube server [http://sonarqube:9000] can not be reached
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 5.433s
INFO: Final Memory: 3M/39M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarQube Scanner execution
ERROR: Unable to execute SonarQube
ERROR: Caused by: Fail to get bootstrap index from server
ERROR: Caused by: sonarqube: Try again
ERROR:
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug
logging.
How can I tell the container to provide the config for the sonar-scanner?
Instead of using the sonar scanner image into my image, I have installed dotnet-sonarscanner using the below command,
dotnet tool install -g dotnet-sonarscanner
I had to install a "coverlet" package to my unit test project by adding the below to my .csproj file of the unit test project.
<PackageReference Include="coverlet.msbuild" Version="2.6.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Now, whenever I want to send sonarqube my coverage results I run below command to generate the coverage file.
dotnet test ./UnitTests/UnitTests.csproj /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
The above command will generate the coverage.opencover.xml file in the project folder.
Now use below commands to send the coverage
dotnet sonarscanner begin /k:"yourprojectkey" /d:sonar.host.url=https://yoursonarqubedomain.com /d:sonar.cs.opencover.reportsPaths="./UnitTests/coverage.opencover.xml" /d:sonar.coverage.exclusions="**Tests*.cs"
dotnet build
dotnet sonarscanner end
you can set the sonarscanner properties like report location and the URL etc., using /d:
I'd like to use bazel in a locked-down environment, one without uncontrolled internet access. I'd like to force bazel to use the locally installed java, instead of downloading one. I could not figure out the required combination of flags - this is what I tried:
$ java -version
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)
$ javac -version
javac 1.8.0_171
$ bazel clean --expunge
$ bazel info release
release 0.24.1
$ bazel build //hello
# This builds a 'hello world' cpp file.
# This rule also downloads some rules, would be nice to avoid it as
INFO: Build completed successfully, 6 total actions well
$ bazel test --nofetch //hello:hello_test
ERROR: /home/erenon/.cache/bazel/_bazel_erenon/afacf41c7e3fc3f4ea7510d344b4de38/external/bazel_tools/tools/jdk/BUILD:218:1: no such package '#remote_java_tools//': to fix, run
bazel fetch //...
External repository #remote_java_tools not found and fetching repositories is disabled. and referenced by '#bazel_tools//tools/jdk:JacocoCoverageRunner'
ERROR: Analysis of target '//hello:hello_test' failed; build aborted: no such package '#remote_java_tools//': to fix, run
bazel fetch //...
External repository #remote_java_tools not found and fetching repositories is disabled.
INFO: Elapsed time: 0.160s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (3 packages loaded, 27 targets configured)
FAILED: Build did NOT complete successfully (3 packages loaded, 27 targets configured)
I get the same results with a more intricate command line:
$ bazel test --nofetch --define=ABSOLUTE_JAVABASE=/usr/lib/jvm/java-8-openjdk-amd64 --host_javabase=#local_jdk//:jdk --javabase=#local_jdk//:jdk --host_java_toolchain=#bazel_tools//tools/jdk:toolchain_hostjdk8 --java_toolchain=#bazel_tools//tools/jdk:toolchain_hostjdk8 //hello:hello_test
INFO: Build options --define, --host_java_toolchain, --host_javabase, and 2 more have changed, discarding analysis cache.
ERROR: /home/erenon/.cache/bazel/_bazel_erenon/afacf41c7e3fc3f4ea7510d344b4de38/external/bazel_tools/tools/jdk/BUILD:218:1: no such package '#remote_java_tools//': to fix, run
bazel fetch //...
External repository #remote_java_tools not found and fetching repositories is disabled. and referenced by '#bazel_tools//tools/jdk:JacocoCoverageRunner'
ERROR: Analysis of target '//hello:hello_test' failed; build aborted: no such package '#remote_java_tools//': to fix, run
bazel fetch //...
External repository #remote_java_tools not found and fetching repositories is disabled.
INFO: Elapsed time: 0.215s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 50 targets configured)
FAILED: Build did NOT complete successfully (0 packages loaded, 50 targets configured)
I tried every combination of the java flags, no luck. I also tried to enable every incompatible change (--all_incompatible_changes), which yields to a different result:
INFO: Build options --incompatible_allow_python_version_transitions, --incompatible_auto_configure_host_platform, --incompatible_cc_coverage, and 24 more have changed, discarding analysis cache.
ERROR: While resolving toolchains for target //hello:hello_test: com.google.devtools.build.lib.packages.BuildFileNotFoundException: no such package '#local_config_platform//': to fix, run
bazel fetch //...
External repository #local_config_platform not found and fetching repositories is disabled.
ERROR: Analysis of target '//hello:hello_test' failed; build aborted: com.google.devtools.build.lib.packages.BuildFileNotFoundException: no such package '#local_config_platform//': to fix, run
bazel fetch //...
External repository #local_config_platform not found and fetching repositories is disabled.
INFO: Elapsed time: 0.228s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (1 packages loaded, 0 targets configured)
FAILED: Build did NOT complete successfully (1 packages loaded, 0 targets configured)
It now looks for #local_config_platform.
Is there a bazel target which I can build from source and includes these dependencies?
Is there a different command line, which enables bazel test --nofetch?
It appear that bootstrapping bazel from source can solve the issue. After downloading bazel-<version>-dist.zip from GitHub, in the unzipped folder:
env EXTRA_BAZEL_ARGS="--host_javabase=#local_jdk//:jdk" bash ./compile.sh
The compiled output is placed into output/bazel. This is a self-contained Bazel binary, without an embedded JDK.
https://docs.bazel.build/versions/master/install-compile-source.html
I'm having a problem with Building TF Hub from Source. Can Anyone please help me out? I've been following the steps as given in https://github.com/tensorflow/hub/blob/master/tensorflow_hub/pip_package/PIP.md
I've installed bazel 0.24.1.
Error I'm Getting:
ERROR: /home/tf_hub/hub/WORKSPACE:17:1: name 'git_repository' is not defined
ERROR: /home/tf_hub/hub/WORKSPACE:40:1: name 'http_archive' is not defined
ERROR: /home/tf_hub/hub/WORKSPACE:47:1: name 'new_http_archive' is not defined
ERROR: Error evaluating WORKSPACE file
ERROR: error loading package '': Encountered error while reading extension file 'tools/build_defs/repo/http.bzl': no such package '#bazel_tools//tools/build_defs/repo': error loading package 'external': Could not load //external package
ERROR: error loading package '': Encountered error while reading extension file 'tools/build_defs/repo/http.bzl': no such package '#bazel_tools//tools/build_defs/repo': error loading package 'external': Could not load //external package
INFO: Elapsed time: 2.552s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)
Bazel Version: 0.24.1
Python Version: 3
Tensorflow Version: 2.0.0a
Commands to Reproduce:
(env)~/tf_hub$ git clone https://github.com/tensorflow/hub
(env)~/tf_hub$ cd hub && bazel build tensorflow_hub/pip_package:build_pip_package
Expected Output: No Error. Build Sucessful
Latest Versions of Bazel Doesn't support git_repository (which is still used by tensorflow_hub), so Uninstalling Bazel 0.24.1 and installing Bazel 0.18.1 worked.
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
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.