Intellij + Bazel Error when compiling Java headers - java

I am learning Spring Boot and am working through this example using Intellij.
Problem:
Intellij's Bazel button --> errors (see example below)
This is the small green icon top right "Sync Project with BUILD Files"
#CrossOrigin annotation causes the error during sandbox compilation or something.
Running command manually bazel build //src/main/java/hello:app --> builds just fine
My understanding of the problem so far:
Intellij's bazel build command includes a flag, --output_groups=intellij-resolve-java-direct-deps, that checks implicit dependencies (see full command + error below).
Normal bazel build //src/main/java/hello:app obviously doesn't include this flag and builds + runs fine.
Questions:
Does anyone know what exactly this flag does?
The error is confusing, stating that it's looking for "another annotation parameter" but I don't believe this to be accurate. If not, what exactly is the parameter I'm supposed to supply? ...and what is <clinit>?
Error Command + Output
/usr/bin/bazel build --tool_tag=ijwb:IDEA:community --keep_going --build_event_binary_file=/tmp/intellij-bep-ef1a54af-ac18-480c-b813-050e261d0a4f --nobuild_event_binary_file_path_conversion --curses=no --color=yes --progress_in_terminal_title=no --noexperimental_run_validations --aspects=#intellij_aspect//:intellij_info_bundled.bzl%intellij_info_aspect --override_repository=intellij_aspect=/home/jordan/.local/share/JetBrains/IdeaIC2021.2/ijwb/aspect --output_groups=intellij-resolve-java-direct-deps -- //src/main/java/hello:app
Loading:
Loading: 0 packages loaded
Analyzing: target //src/main/java/hello:app (0 packages loaded, 0 targets configured)
INFO: Analyzed target //src/main/java/hello:app (5 packages loaded, 184 targets configured).
INFO: Found 1 target...
[0 / 39] [Prepa] BazelWorkspaceStatusAction stable-status.txt
ERROR: /home/jordan/Documents/swe/rules_jvm_external/examples/spring_boot/src/main/java/hello/BUILD:1:13: Compiling Java headers src/main/java/hello/liblib-hjar.jar (2 source files) failed: (Exit 1): java failed: error executing command external/remotejdk11_linux/bin/java -Xverify:none -XX:+UseParallelOldGC -XX:-CompactStrings '--patch-module=java.compiler=external/remote_java_tools_linux/java_tools/java_compiler.jar' ... (remaining 42 argument(s) skipped)
Use --sandbox_debug to see verbose messages from the sandbox
src/main/java/hello/HelloController.java:7: error: missing required annotation argument: <clinit>
#CrossOrigin
^
src/main/java/hello/HelloController.java:11: error: missing required annotation argument: <clinit>
#CrossOrigin
^
Aspect #intellij_aspect//:intellij_info_bundled.bzl%intellij_info_aspect of //src/main/java/hello:app failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.460s, Critical Path: 0.33s
INFO: 2 processes: 2 internal.
FAILED: Build did NOT complete successfully
INFO: Build Event Protocol files produced successfully.
FAILED: Build did NOT complete successfully
FAILED: Build did NOT complete successfully
Successful Command + Output
(removed flag --output_groups=intellij-resolve-java-direct-deps)
/usr/bin/bazel build --tool_tag=ijwb:IDEA:community --keep_going --build_event_binary_file=/tmp/intellij-bep-ef1a54af-ac18-480c-b813-050e261d0a4f --nobuild_event_binary_file_path_conversion --curses=no --color=yes --progress_in_terminal_title=no --noexperimental_run_validations --aspects=#intellij_aspect//:intellij_info_bundled.bzl%intellij_info_aspect --override_repository=intellij_aspect=/home/jordan/.local/share/JetBrains/IdeaIC2021.2/ijwb/aspect -- //src/main/java/hello:app
Loading:
Loading: 0 packages loaded
Analyzing: target //src/main/java/hello:app (0 packages loaded, 0 targets configured)
INFO: Analyzed target //src/main/java/hello:app (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
[0 / 1] [Prepa] BazelWorkspaceStatusAction stable-status.txt
Aspect #intellij_aspect//:intellij_info_bundled.bzl%intellij_info_aspect of //src/main/java/hello:app up-to-date (nothing to build)
INFO: Elapsed time: 0.034s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Build completed successfully, 1 total action
INFO: Build Event Protocol files produced successfully.
INFO: Build completed successfully, 1 total action

Bazel is still working to support Java 11 and there are Java annotation processors which appear to be hardcoded to JDK 8.
See this GitHub issue which refers to a
Temporary fix
--java_header_compilation=false
Note that this won't solve the issue when using Intellij's bazel button. This will only fix running the command manually (with the --java_header_compilation=false flag).
Long-term fix in the upcoming release (6.0.0)
I installed the pre-release 6.0.0 Bazel from the source code using these directions, which includes the implemented fix. This solved the problem. Now I can use two different releases of bazel - 6.0.0 by calling bazel_dev or the latest main release (4.2.1) by simply calling bazel.
Point to /some/path/to/bazel_dev binary in Intellij's Bazel settings.

Related

Bazel with Java 11 on Ubuntu

I am trying to use Java 11 for my Java Homework. It works fine on my OS X machine, but I have JDK 13 installed on my machine. My instructor uses Ubuntu and does not have the latest java installed. How Can I get Bazel to use JAVA 11 without requiring my instructor to update his JDK.
My .bazelrc is as follows:
test --test_output=errors
test --cache_test_results=yes
test --java_toolchain=#bazel_tools//tools/jdk:toolchain_java11
And when I run:
bazel test java/test/edu/berkeley/cs/util:{hashset,hashmap}
I get this wonderfull error.
Starting local Bazel server and connecting to it...
INFO: Writing tracer profile to '/home/tomgrant/.cache/bazel/_bazel_tomgrant/75fd013422b9b35862a74918dc983c19/command.profile.gz'
INFO: Analyzed 2 targets (23 packages loaded, 287 targets configured).
INFO: Found 2 test targets...
INFO: Deleting stale sandbox base /home/tomgrant/.cache/bazel/_bazel_tomgrant/75fd013422b9b35862a74918dc983c19/sandbox
ERROR: /home/tomgrant/.cache/bazel/_bazel_tomgrant/75fd013422b9b35862a74918dc983c19/external/bazel_tools/tools/jdk/BUILD:319:1: Action external/bazel_tools/tools/jdk/platformclasspath.jar failed (Exit 1) java failed: error executing command external/remotejdk11_linux/bin/java -XX:+IgnoreUnrecognizedVMOptions '--add-exports=jdk.compiler/com.sun.tools.javac.platform=ALL-UNNAMED' -cp ... (remaining 4 argument(s) skipped)
Use --sandbox_debug to see verbose messages from the sandbox
Exception in thread "main" java.lang.IllegalArgumentException: external/local_jdk
at jdk.compiler/com.sun.tools.javac.file.Locations$SystemModulesLocationHandler.isCurrentPlatform(Locations.java:1862)
at jdk.compiler/com.sun.tools.javac.file.Locations$SystemModulesLocationHandler.update(Locations.java:1851)
at jdk.compiler/com.sun.tools.javac.file.Locations$SystemModulesLocationHandler.handleOption(Locations.java:1798)
at jdk.compiler/com.sun.tools.javac.file.Locations.handleOption(Locations.java:2062)
at jdk.compiler/com.sun.tools.javac.file.BaseFileManager.handleOption(BaseFileManager.java:269)
at jdk.compiler/com.sun.tools.javac.file.BaseFileManager$2.handleFileManagerOption(BaseFileManager.java:222)
at jdk.compiler/com.sun.tools.javac.main.Option.process(Option.java:1138)
at jdk.compiler/com.sun.tools.javac.main.Option.handleOption(Option.java:1086)
at jdk.compiler/com.sun.tools.javac.file.BaseFileManager.handleOption(BaseFileManager.java:232)
at jdk.compiler/com.sun.tools.javac.main.Arguments.doProcessArgs(Arguments.java:390)
at jdk.compiler/com.sun.tools.javac.main.Arguments.processArgs(Arguments.java:347)
at jdk.compiler/com.sun.tools.javac.main.Arguments.init(Arguments.java:246)
at jdk.compiler/com.sun.tools.javac.api.JavacTool.getTask(JavacTool.java:185)
at DumpPlatformClassPath.dumpJDK9AndNewerBootClassPath(DumpPlatformClassPath.java:106)
at DumpPlatformClassPath.main(DumpPlatformClassPath.java:67)
Caused by: java.nio.file.NoSuchFileException: external/local_jdk
at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116)
at java.base/sun.nio.fs.UnixFileSystemProvider.isSameFile(UnixFileSystemProvider.java:333)
at java.base/java.nio.file.Files.isSameFile(Files.java:1530)
at jdk.compiler/com.sun.tools.javac.file.Locations$SystemModulesLocationHandler.isCurrentPlatform(Locations.java:1860)
... 14 more
INFO: Elapsed time: 8.063s, Critical Path: 0.26s
INFO: 3 processes: 3 linux-sandbox.
FAILED: Build did NOT complete successfully
//java/test/edu/berkeley/cs/util:hashset NO STATUS
FAILED: Build did NOT complete successfully
If anyone can solve this will be glad to send you a bag of Blue Bottle beans or something similar that costs $20 =D
I don't know I understand your question correctly, but I'm looking for the same issue right now.
So far I got one answer from this link from Bazel Dev! from gerrit.googlesource.com
And please look at this section:
[[java-11]]
==== Java 11 support
Java 11 is supported through alternative java toolchain
link:https://docs.bazel.build/versions/master/toolchains.html[Bazel option].
To build Gerrit with Java 11, specify JDK 11 java toolchain:
$ bazel build \
--host_javabase=#bazel_tools//tools/jdk:remote_jdk11 \
--javabase=#bazel_tools//tools/jdk:remote_jdk11 \
--host_java_toolchain=#bazel_tools//tools/jdk:toolchain_java11 \
--java_toolchain=#bazel_tools//tools/jdk:toolchain_java11 \
:release

Build OpenJDK 9 in CentOS5

I was trying to build OpenJDK 9 in Centos 5. I used
sh ./configure --disable-warnings-as-errors
make all
I am getting the following error.
Building target 'all' in configuration 'linux-x86_64-normal-server-release'
/root/jdk9/build/linux-x86_64-normal-server-
release/support/native/java.base/libjava/io_util_md.o: In function
`handleSetLength':
/root/jdk9/jdk/src/java.base/unix/native/libjava/io_util_md.c:228:
undefined reference to `fallocate64'
collect2: ld returned 1 exit status
/usr/bin/objcopy: '/root/jdk9/build/linux-x86_64-normal-server-
release/support/modules_libs/java.base/libjava.so': No such file
gmake[3]: *** [/root/jdk9/build/linux-x86_64-normal-server-
release/support/modules_libs/java.base/libjava.so] Error 1
gmake[2]: *** [java.base-libs] Error 2
ERROR: Build failed for target 'all' in configuration 'linux-x86_64-normal-
server-release' (exit code 2)
=== Output from failing command(s) repeated here ===
* For target support_native_java.base_libjava_BUILD_LIBJAVA_link:
/root/jdk9/build/linux-x86_64-normal-server-
release/support/native/java.base/libjava/io_util_md.o: In function
`handleSetLength':
/root/jdk9/jdk/src/java.base/unix/native/libjava/io_util_md.c:228:
undefined reference to `fallocate64'
collect2: ld returned 1 exit status
* All command lines available in /root/jdk9/build/linux-x86_64-normal-
server-release/make-support/failure-logs.
=== End of repeated output ===
No indication of failed target found.
Hint: Try searching the build log for '] Error'.
Hint: See common/doc/building.html#troubleshooting for assistance.
make[1]: *** [main] Error 2
make: *** [all] Error 2
I also tried other make targets such as make images and make install. But still getting the same error. My GCC version is gcc (GCC) 4.4.7 which I manually installed because Centos 5 by default has an older version.
Building JDK requires at least GCC 5.0 (see Building the JDK: CC).
This seems to be a problem in the glibc version (see redhat-issue, util-linux). So, updating your glibc to the latest version might solve it.
If you don't want to update your system's glibc, here is another alternative:
By looking at the man page of fallocate, we find that the description mentions that posix_fallocate(3) is a portable, POSIX.1-specified version of it, in case the mode parameter has the default value (0). The same applies to fallocate64.
Since all the occurrences of the aforementioned error already use the default mode value, you can replace them with posix_fallocate64() (instead of commenting them out as you mentioned in another comment).
The denoted man page says that:
This default behavior [of fallocate with mode=0] closely resembles the
behavior of the posix_fallocate(3) library function, and is intended
as a method of optimally implementing that function.

Upgraded Fedora 24, Gradle status text does not show

Prior to upgrading to Fedora 24, I would see output from Gradle like the following:
> Loading
> Configuring project 0/20
> Executing test 39 of 4049, 12 skipped.
I've read that users often set TERM=dumb in order to disable this output; however, my TERM environment variable is set to xterm-256color.
Could someone tell me what I need to set or change under Fedora 24 (which seemed to exist in Fedora 23) to allow me to get this Gradle output?
The problem is that Gradle is wanting to use ncurses5 where it seems Fedora 24 install comes with a newer version, thus causing the issue. This can be seen by running gradle --debug and seeing the following output:
[DEBUG] [org.gradle.internal.nativeintegration.services.NativeServices] Unable to load from native-platform backed Consol
eDetector. Continuing with fallback. Failure: net.rubygrapefruit.platform.NativeException: Failed to load native library 'libnative-pl
atform-curses.so' for Linux amd64.
caused by: java.lang.UnsatisfiedLinkError: /home/dkowis/.gradle/native/19/linux-amd64/libnative-platform-curses.so: libncurses.so.5: c
annot open shared object file: No such file or directory
The temporary solution is to create a symbolic link to the new libncurses.so.6 library as follows:
sudo ln -s /usr/lib64/libncurses.so.6 /usr/lib64/libncurses.so.5
After doing this, Gradle now outputs the build status text as it did previously.

Can't build cordova projects

I have a problem with setting up the work environment for Cordova on Windows 7 for Android. I use NetBeans 8 and followed this guide: Link Here
New project -> Cordova -> Hello World Template.
Whenever I try to build a Cordova project (in NetBeans) I get this message:
BUILD FAILED
C:\Users\Administrator\Documents\NetBeansProjects\HTML5Application2\platforms\android\build.xml:90: Cannot find C:\Users\Administrator\SkyDrive\Skolegang\Dataingeniør\Android\adt-bundle-windows-x86_64-20130729\sdk\tools\ant\build.xml imported from C:\Users\Administrator\Documents\NetBeansProjects\HTML5Application2\platforms\android\build.xml
Total time: 0 seconds
C:\Users\Administrator\Documents\NetBeansProjects\HTML5Application2\platforms\android\cordova\node_modules\q\q.js:126
throw e;
Error code 1 for command: cmd with args: /s,/c,ant,debug,-f,C:\Users\Administrator\Documents\NetBeansProjects\HTML5Application2\platforms\android\build.xml,-Dout.dir=ant-build,-Dgen.absolute.dir=ant-gen
Error: C:\Users\Administrator\Documents\NetBeansProjects\HTML5Application2\platforms\android\cordova\run.bat: Command failed with exit code 8
at ChildProcess.whenDone (C:\Users\Administrator\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\cordova\superspawn.js:131:23)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:743:16)
at Process.ChildProcess._handle.onexit (child_process.js:810:5)
Command finished with error code 8: C:\Users\Administrator\Documents\NetBeansProjects\HTML5Application2\platforms\android\cordova\run.bat --emulator
C:\Users\Administrator\Documents\NetBeansProjects\HTML5Application2\nbproject\build.xml:272: exec returned: 1
BUILD FAILED (total time: 47 seconds)
I have googled it for hours but can't seem to find a solution. Some people get some of the same errors(not exact, but similar), but the solutions did not work for me. One issue was regarding Java 8 and ant versions beneath 1.9.0 (I use Node 0.10.26, java 1.7.0_25, cordova 3.5.0-0.2.4 and ant 1.9.4). I also tried to create a new project with the console (CMD), but it gives the exact same error when I build. It's no problem to create the project, nor adding Android as a platform, the problem is building the project. I think the environment variables are set correctly since the java, node, ant and cordova commands work fine in cmd/powershell, and the check_reqs.bat said that the environment was fine.
It's this line that creates the error: <import file="${sdk.dir}/tools/ant/build.xml" />. This is the rest of the message: Cannot find C:\Users\Administrator\SkyDrive\Skolegang\Dataingeniør\Android\adt-bundle-windows-x86_64-20130729\sdk\tools\ant\build.xml imported from C:\Users\Administrator\Documents\NetBeansProjects\HTML5Application2\platforms\android\build.xml.
Here is the error I get in the command window (not using NetBeans):
PS C:\Users\Administrator\Desktop\test\fakeApp> cordova build android
Running command: C:\Users\Administrator\Desktop\test\fakeApp\platforms\android\cordova\build.bat
Buildfile: C:\Users\Administrator\Desktop\test\fakeApp\platforms\android\build.xml
BUILD FAILED
C:\Users\Administrator\Desktop\test\fakeApp\platforms\android\build.xml:90: Cannot find C:\Users\Administrator\SkyDrive\
Skolegang\Dataingeni├©r\Android\adt-bundle-windows-x86_64-20130729\sdk\tools\ant\build.xml imported from C:\Users\Admini
strator\Desktop\test\fakeApp\platforms\android\build.xml
Total time: 0 seconds
Error code 1 for command: cmd with args: /s,/c,ant,debug,-f,C:\Users\Administrator\Desktop\test\fakeApp\platforms\androi
d\build.xml,-Dout.dir=ant-build,-Dgen.absolute.dir=ant-gen
Error: C:\Users\Administrator\Desktop\test\fakeApp\platforms\android\cordova\build.bat: Command failed with exit code 2
at ChildProcess.whenDone (C:\Users\Administrator\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\s
rc\cordova\superspawn.js:131:23)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:743:16)
at Process.ChildProcess._handle.onexit (child_process.js:810:5)
I thought maybe it was a path issue since I have a special letter in the path were the NetBeansProjects are stored (and it's pretty long too), but creating a test directory at C:\ and creating the project with the command window gave the same error. I'm new at Cordova so I'm sure there's an easy solution, thanks in advance.
I solved it, though I tried to create a cordova project outside the OneDrive folder I did not think of the SDK path (which also were stored in OneDrive). By moving the SDK files to C: (the path could probably not contain the special letter 'ø') and changing the path of the environment variables (and the SDK path in NetBeans) it now runs perfectly.

Cobertura 2.0.3 - unable to instrument

I am using Corbetura-2.0.3 with java 1.7 and I am trying to instrument the classes in our build system via command line. Stuck at instrumenting classes. Please assist.
Here is the command:
./cobertura-instrument.sh --basedir /ariba/9r2_sourcing/roots-S49r2/install/classes/ariba.app.approvable.zip --destination /ariba/9r2_sourcing/Instrument -auxClasspath /ariba/9r2_sourcing/roots-S49r2/install/classes
Wherein,
/ariba/9r2_sourcing/roots-S49r2/install/classes/ariba.app.approvable.zip – zip containing classes which I would like to instrument
/ariba/9r2_sourcing/Instrument – Folder to save instrumented classes
/ariba/9r2_sourcing/roots-S49r2/install/classes – path where all other reference classes are present.
Output:
-bash-4.1$ ./cobertura-instrument.sh --basedir /ariba/9r2_sourcing/roots-S49r2/install/classes/ariba.app.approvable.zip --destination /ariba/9r2_sourcing/Instrument -auxClasspath /ariba/9r2_sourcing/roots-S49r2/install/classes
Cobertura 2.0.3 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
Apr 29, 2014 4:53:27 AM net.sourceforge.cobertura.coveragedata.CoverageDataFileHandler loadCoverageData
INFO: Cobertura: Loaded information on 0 classes.
Apr 29, 2014 4:53:27 AM net.sourceforge.cobertura.coveragedata.CoverageDataFileHandler saveCoverageData
INFO: Cobertura: Saved information on 0 classes.
Also tried with:
‘archivesdepth’ parameter as well; it gives the same above error.
I have updated the ‘cobertura-instrument.sh’ file with the right versions of jars present in Cobertura installed location.
I see , in command you have not mentioned classes which you need to instrument.
Example: Below command works.
sh cobertura-instrument.sh --basedir `pwd` GenerateReports.class My_lib.class
Note:
Classes need to be mentioned as complete filename (e.g. mycls.class)
-auxClasspath : Add any classes/jars that cobertura is unable to find during instrumentation i.e. classes to exclude from coverage

Categories

Resources