Recently I've observed a (at least for me) strange behavior of the Java Compiler "ToolProvider.getSystemJavaCompiler()".
If I try to compile a not-compilable java file in a "bare" maven project, I can obtain the errors as expected.
If I add certain dependencies (I've first observed this when adding log4j), the compiler does not provide any information regarding compiler errors anymore.
To demonstrate this behavior, I've created an example repository for this: https://github.com/dfuchss/JavaCompilerIsStrange
In this repository I've added a simple main method that tries to parse the AST of an invalid Java File. The main method throws an exception if the diagnostics object contains no errors. This main method will be invoked by a single test.
In my pom.xml I've created a profile "strange" that simply adds a dependency to the project (that is not used but obviously will be added to the classpath after activating the profile). For this example it's the "metainf-services" dependency.
In the run.sh file, I simply execute mvn test twice.
First without the profile activated and after that with the activated profile.
If you run the script you get a successful test (because the invalid syntax was detected) and an failed test (because the invalid syntax was not detected after adding the dependency)
## Build without activated profile
[INFO] Scanning for projects...
[....]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running SimpleExecTest
src/main/resources/Example.java:4: error: ';' expected
System.out.println("Hello World!")
^
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.19 s - in SimpleExecTest
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.832 s
[INFO] Finished at: 2022-06-24T00:57:46+02:00
[INFO] ------------------------------------------------------------------------
## Build with activated profile
[INFO] Scanning for projects...
[....]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running SimpleExecTest
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.203 s <<< FAILURE! - in SimpleExecTest
[ERROR] SimpleExecTest.testMain Time elapsed: 0.171 s <<< ERROR!
java.lang.Error: Shall not be possible to compile.
at org.fuchss.Main.main(Main.java:46)
at SimpleExecTest.testMain(SimpleExecTest.java:7)
[....]
[INFO]
[INFO] Results:
[INFO]
[ERROR] Errors:
[ERROR] SimpleExecTest.testMain:7 ยป Shall not be possible to compile.
[INFO]
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.323 s
[INFO] Finished at: 2022-06-24T00:57:54+02:00
[INFO] ------------------------------------------------------------------------
[....]
Does anyone has an idea how to resolve this behavior?
EDIT:
mvn dependency:tree does not show any further dependency (compile) for "metainf-services"
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # strange ---
[INFO] org.fuchss:strange:jar:1.0-SNAPSHOT
[INFO] +- org.junit.jupiter:junit-jupiter-engine:jar:5.8.2:test
[INFO] | +- org.junit.platform:junit-platform-engine:jar:1.8.2:test
[INFO] | | +- org.opentest4j:opentest4j:jar:1.2.0:test
[INFO] | | \- org.junit.platform:junit-platform-commons:jar:1.8.2:test
[INFO] | +- org.junit.jupiter:junit-jupiter-api:jar:5.8.2:test
[INFO] | \- org.apiguardian:apiguardian-api:jar:1.1.2:test
[INFO] \- org.kohsuke.metainf-services:metainf-services:jar:1.9:compile
Edit II: I've added the output mvn -X clean verify without and with activated profile to https://github.com/dfuchss/JavaCompilerIsStrange/blob/main/result.txt
You can "fix" this problem by disabling annotation processing:
final JavaCompiler.CompilationTask task = javac.getTask(
null, fileManager, listener, List.of("-proc:none"), null, javaFiles
);
This looks like a bug in the JDK to me: when annotation processing is meant to happen (which doesn't seem to require an explicit annotation processor being used, hence this problem occurs with dependencies like log4j) the error reporting is wrapped in a DeferredDiagnosticHandler. I think the intention is that after the processing is done, reportDeferredDiagnostics() will be called, which will transfer the diagnostics to the original handler, but for some reason this isn't happening.
A bit more time with the debugger would answer this properly.
Related
I'm running Maven in a CI environment and want to see some of its log output - but I don't want to see routine messages about downloading artifacts etc.
I can use -q but that suppresses everything useful too.
Maven uses slf4j and by default uses the slf4j-simple backend so there's no logging.properties etc, and anyway how would I even find out which class generates the log messages?
e.g. if I have
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] XXX JDBC Driver - JDBC 4.2 [bundle]
[INFO] XXX JDBC Driver aggregate [pom]
[INFO]
[INFO] -----------------< XXX:XXX >------------------
[INFO] Building XXX JDBC Driver - JDBC 4.2 XXXX [1/2]
[INFO] -------------------------------[ bundle ]-------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # XXXX-jdbc ---
[INFO] Deleting XXXX/target
[INFO]
[INFO] --- maven-enforcer-plugin:1.3.1:enforce (enforce-java) # XXX-jdbc ---
[INFO]
[INFO] --- build-helper-maven-plugin:1.5:parse-version (parse-version) # XXXX-jdbc ---
[INFO]
[INFO] --- properties-maven-plugin:1.0-alpha-2:read-project-properties (default) # XXXX-jdbc ---
[WARNING] Ignoring missing properties file: XXX/build.local.properties
[INFO]
[INFO] --- jcp:6.0.1:preprocess (preprocessSources) # XXX-jdbc ---
[INFO] Added MAVEN property mvn.project.name=XXX JDBC Driver - JDBC 4.2
[INFO] Added MAVEN property mvn.project.version=XX.YY.ZZ
.... blah blah blah ...
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running XXX.TestSuite
Tests run: 58, Failures: 0, Errors: 0, Skipped: 1, Time elapsed: 6.43 sec
and for this task I just want the test output, how do I do that?
Maven uses slf4j-simple. Its configuration is loaded from the classpath in a file simplelogger.properties. You can modify the classpath to put your own copy of this file first, but you can also override these properties by setting system properties.
First re-run your build with -D-Dorg.slf4j.simpleLogger.showLogName=true so you can see which classes the logs are coming from. Then adjust log levels as desired by setting additional properties named -Dorg.slf4.simpleLogger.log.[[classname]]=[[level]].
You may require the -B (batch) flag too.
I find it convenient to set these in a .mvn/maven.config file in my project, but you can use MAVEN_OPTS or the command line instead. An example .mvn/maven.config might be:
-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
-Dorg.slf4j.simpleLogger.log.com.igormaznitsa.jcp.maven.PreprocessorMojo=warn
-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.event.ExecutionEventLogger=warn
-Dorg.slf4j.simpleLogger.log.org.apache.maven.shared.filtering.DefaultMavenResourcesFiltering=warn
-Dorg.slf4j.simpleLogger.log.org.apache.maven.plugin.clean.CleanMojo=warn
-Dorg.slf4j.simpleLogger.showLogName=true
Note that putting these options in a simplelogging.properties of the project being compiled will not work, it must be in the classpath of the maven runtime.
Also beware that .mvn/maven.config doesn't appear to support comments. I tried #, ;, //, /* .. */.
I'm exploring DocdokuPLM.
To Install docdoku I have used the docker configuration file which can be found here.
Using it have configured and installed Docdokuplm in my localhost.
Now not sure why sample project is not getting imported.
To import and check sample project I have used the following command.
sudo ./platform-ctl insert-sample MY_LOGIN_USER_ID MY_PASSWORD
While running the command to import sample project i'm getting the following error:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 16.571 s
[INFO] Finished at: 2019-01-31T07:29:36+00:00 [INFO] Final Memory: 34M/301M
[INFO] ------------------------------------------------------------------------
[INFO] - No workspace name supplied, generating one...
[INFO] - Using wks-a72fca63 as workspace name
[INFO] - Starting load process...
[INFO] - Checking server availability...
[INFO] - Creating your account...
[INFO] - Creating account [sommesh29]
[INFO] - Cannot create account, trying to use given credentials for next operations
[INFO] - Creating workspace...
[INFO] - Adding user sommesh29 to workspace wks-a72fca63
[SEVERE] - Ooops, something went wrong while loading sample data : Not Found Not Foundcom.docdoku.api.client.ApiException: Not Found
at com.docdoku.api.client.ApiClient.handleResponse(ApiClient.java:838)
at com.docdoku.api.client.ApiClient.execute(ApiClient.java:773)
at com.docdoku.api.client.ApiClient.execute(ApiClient.java:757)
at com.docdoku.api.services.WorkspacesApi.addUserWithHttpInfo(WorkspacesApi.java:833)
at com.docdoku.api.services.WorkspacesApi.addUser(WorkspacesApi.java:819)
at com.docdoku.loaders.SampleLoader.addUserToWorkspace(SampleLoader.java:304)
at com.docdoku.loaders.SampleLoader.load(SampleLoader.java:88)
at com.docdoku.loaders.Main.main(Main.java:73)
what am i doing wrong ?
Is this a issue from my side or is this issue occurring from Docker file?
I have been trying to scan a java project (ArgoUML) with the sonar scanner and I'm getting the following error when using sonar-scanner in the project directory:
ERROR: Error during SonarQube Scanner execution
ERROR: Please provide compiled classes of your project with sonar.java.binaries property
The project is cloned from this repo:
https://github.com/cscorley/argouml-mirror
I tried building with maven using mvn package and mvn install but every time I'm getting an error. The last error that I got is:
Results :
Failed tests:
Tests in error:
Tests run: 1106, Failures: 2, Errors: 8, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] argouml-core 0.35.2-SNAPSHOT ....................... SUCCESS [ 0.898 s]
[INFO] argouml-core-model ................................. SUCCESS [ 0.783 s]
[INFO] argouml-core-model-mdr ............................. SUCCESS [ 8.167 s]
[INFO] argouml-core-model-euml ............................ SUCCESS [ 0.162 s]
[INFO] argouml-app ........................................ FAILURE [04:55 min]
[INFO] argouml-core-notation .............................. SKIPPED
[INFO] argouml-core-transformer ........................... SKIPPED
[INFO] argouml-core-umlpropertypanels ..................... SKIPPED
[INFO] argouml-core-diagrams-activity2 .................... SKIPPED
[INFO] argouml-core-diagrams-class2 ....................... SKIPPED
[INFO] argouml-core-diagrams-sequence2 .................... SKIPPED
[INFO] argouml-core-diagrams-state2 ....................... SKIPPED
[INFO] argouml-core-diagrams-structure2 0.35.2-SNAPSHOT ... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 05:05 min
[INFO] Finished at: 2018-05-03T12:07:31+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.8.1:test (default-test) on project argouml: There are test failures.
[ERROR]
[ERROR] Please refer to /Users/redhood148/Documents/git/argouml-mirror/src/argouml-app/target/surefire-reports for the individual test results.
Any suggestions how I can fix this?
Let me know if you need more info.
Thanks.
I do not exactly know the reason for this, but can help you with the solution that worked for me.
You must have mentioned the source path under "sonar.sources" in your configuration specifying the source package from where code needs to be scanned.
eg. sonar.sources=/home/workspace/codecoveragejob/Test_project/Test_project_service/src
along with this property, set another property under "sonar.java.binaries" and provide same value as "sonar.sources".
So it would look something like this:
sonar.sources=/home/workspace/codecoveragejob/Test_project/Test_project_service/src
sonar.java.binaries= /home/workspace/codecoveragejob/Test_project/Test_project_service/src
Hope that helps...
You have unit tests in argouml-app that are failing. You can either fix the code or the tests so that they pass. Or you can just skip the tests by running mvn install -DskipTests when building the project. This will allow you to build the project and produce the binaries that Sonar needs.
Having this class in a maven project:
package test;
public class A {
/**
* Used by {#link B#setC(C)}.
* Used by {#link A.B#setC(C)}.
* Used by {#link test.A.B#setC(C)}.
*/
public class C {
}
public class B {
public void setC(C c) {
System.out.println("hello!");
}
}
}
Gives me this warning:
C:\Users\user\workspace\t>mvn clean javadoc:javadoc
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building t 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # t ---
[INFO] Deleting C:\Users\user\workspace\t\target
[INFO]
[INFO] >>> maven-javadoc-plugin:2.10.4:javadoc (default-cli) > generate-sources # t >>>
[INFO]
[INFO] <<< maven-javadoc-plugin:2.10.4:javadoc (default-cli) < generate-sources # t <<<
[INFO]
[INFO] --- maven-javadoc-plugin:2.10.4:javadoc (default-cli) # t ---
[WARNING] Source files encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO]
Loading source files for package test...
Constructing Javadoc information...
Standard Doclet version 1.8.0_101
Building tree for all the packages and classes...
Generating C:\Users\user\workspace\t\target\site\apidocs\test\A.html...
Generating C:\Users\user\workspace\t\target\site\apidocs\test\A.B.html...
Generating C:\Users\user\workspace\t\target\site\apidocs\test\A.C.html...
Generating C:\Users\user\workspace\t\target\site\apidocs\test\package-frame.html...
Generating C:\Users\user\workspace\t\target\site\apidocs\test\package-summary.html...
Generating C:\Users\user\workspace\t\target\site\apidocs\test\package-tree.html...
Generating C:\Users\user\workspace\t\target\site\apidocs\constant-values.html...
Generating C:\Users\user\workspace\t\target\site\apidocs\test\class-use\A.html...
Generating C:\Users\user\workspace\t\target\site\apidocs\test\class-use\A.C.html...
Generating C:\Users\user\workspace\t\target\site\apidocs\test\class-use\A.B.html...
Generating C:\Users\user\workspace\t\target\site\apidocs\test\package-use.html...
Building index for all the packages and classes...
Generating C:\Users\user\workspace\t\target\site\apidocs\overview-tree.html...
Generating C:\Users\user\workspace\t\target\site\apidocs\index-all.html...
Generating C:\Users\user\workspace\t\target\site\apidocs\deprecated-list.html...
Building index for all classes...
Generating C:\Users\user\workspace\t\target\site\apidocs\allclasses-frame.html...
Generating C:\Users\user\workspace\t\target\site\apidocs\allclasses-noframe.html...
Generating C:\Users\user\workspace\t\target\site\apidocs\index.html...
Generating C:\Users\user\workspace\t\target\site\apidocs\help-doc.html...
3 warnings
[WARNING] Javadoc Warnings
[WARNING] C:\Users\user\workspace\t\src\main\java\test\A.java:9: warning - Tag #link: can't find setC(C) in test.A.B
[WARNING] C:\Users\user\workspace\t\src\main\java\test\A.java:9: warning - Tag #link: can't find setC(C) in test.A.B
[WARNING] C:\Users\user\workspace\t\src\main\java\test\A.java:9: warning - Tag #link: can't find setC(C) in test.A.B
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.521 s
[INFO] Finished at: 2016-12-02T10:10:28+01:00
[INFO] Final Memory: 17M/309M
[INFO] ------------------------------------------------------------------------
C:\Users\user\workspace\t>
Why does javadoc say he can not find the method?
Try Used by {#link A.B#setC(A.C)}.
Here's a sample Error message from Errai compilation:
[INFO] Rule did not match
[INFO] Found better fallback match for <replace-with class='com.google.gwt.logging.client.LogConfiguration.LogConfigurationImplRegular'/>
[INFO] Checking rule <generate-with class='org.jboss.errai.marshalling.rebind.MarshallerGenerator'/>
[INFO] Checking if all subconditions are true (<all>)
[INFO] <when-assignable class='org.jboss.errai.marshalling.client.api.GeneratedMarshaller'/>
[INFO] Yes, the requested type was assignable
[INFO] Yes: All subconditions were true
[INFO] Rule was a match and will be used
[INFO] Invoking generator org.jboss.errai.marshalling.rebind.MarshallerGenerator
[INFO] Type 'org.jboss.errai.marshalling.client.api.Marshaller_a_j_l_StackTraceElement_D1_Impl' already exists and will not be re-created
[INFO] Generator returned type 'org.jboss.errai.marshalling.client.api.Marshaller_a_j_l_StackTraceElement_D1_Impl; mode USE_EXISTING; in 0 ms
[INFO] Rebind result was org.jboss.errai.marshalling.client.api.Marshaller_a_j_l_StackTraceElement_D1_Impl
[INFO] Shutting down PersistentUnitCache thread
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 03:52 min
My question is how to get into the actual error that needs to be fixed or at least something more detailed.