Convenience (maven/gradle) dependency to overcome log4j's warning: "no appenders could be found for logger" and just write to console - maven

I am not looking on how to configure log4j so that it actually has an appender, but I rather wondered whether there exists a convenience library (similar to slf4j-simple) which basically just logs everything to console without the need to configure anything else.
Just adding that library and it logs to console.

While writing the question, I remembered, that for sl4fj there actually already is something like that, e.g. there is the Log4j to SLF4J Adapter which basically routes all the log4j logging statements to SLF4J. For version 1.2 such a bridge exits also: org.slf4j:log4j-over-slf4j:1.7.25
From there I can just use slf4j-simple or logback-classic and it will write to console. So for now (until someone offers me a single dependency ;-)) I will use something like the following, which does what I was looking for:
compile "org.slf4j:slf4j-api:1.7.25"
compile "org.slf4j:log4j-over-slf4j:1.7.25"
compile "ch.qos.logback:logback-classic:1.2.3" // or: compile "org.slf4j:slf4j-simple:1.7.25"
For log4j 2 it works as follows:
compile "org.apache.logging.log4j:log4j-to-slf4j:2.11.1"
compile "org.slf4j:slf4j-api:1.7.25"
compile "ch.qos.logback:logback-classic:1.2.3" // or: compile "org.slf4j:slf4j-simple:1.7.25"
Actually in my case I only required the following two (even though the 1.2-log4j-warning was displayed, but probably some other dependencies were already in place as well ;-)):
implementation("ch.qos.logback:logback-classic:1.2.3")
implementation("org.apache.logging.log4j:log4j-to-slf4j:2.11.1")

Related

Use Groovy app and test code in combination with jlink solution for bundling JavaFX

This follows on from this excellent solution to the question of how to get Gradle to bundle up JavaFX with your distributions.
NB specs: Linux Mint 18.3, Java 11, JavaFX 13.
That stuff, involving jlink and a module-info.java, is beyond my pay grade (although I'm trying to read up on these things).
I want to move to using Groovy in my app and test code (i.e. Spock) rather than Java. The trouble is, the minute I include the "normal" dependency in my build.gradle i.e.
implementation 'org.codehaus.groovy:groovy-all:2.5.9'
and try to build, I get multiple errors:
mike#M17A ~/IdeaProjects/TestProj $ ./gradlew build
> Configure project :
Found module name 'javafx.jlink.example.main'
> Task :compileTestJava FAILED
error: the unnamed module reads package org.codehaus.groovy.tools.shell.util from both org.codehaus.groovy.groovysh and org.codehaus.groovy
[...]
error: the unnamed module reads package groovy.xml from both org.codehaus.groovy and org.codehaus.groovy.xml
[...]
error: module org.codehaus.groovy.ant reads package groovy.lang from both org.codehaus.groovy and org.codehaus.groovy.test
error: module org.codehaus.groovy.ant reads package groovy.util from both org.codehaus.groovy.xml and org.codehaus.groovy.ant
100 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileTestJava'.
Yes, 100 errors... probably more! By commenting out various things I think I've come to the conclusion that some Groovy dependency is being injected by the jlink stuff. Fine, I can live with that (although it'd be nice to know what version of Groovy it is).
The trouble is, even if I omit the Groovy dependency line, the same errors occur when I try to introduce the Spock dependency:
testImplementation 'org.spockframework:spock-core:1.2-groovy-2.5'
Has anyone got any idea what's going on here and what to do about it?
I searched for an answer. I didn't find a good solution.
According to this, it seems that Groovy is currently not really compatible with Java modules. It is due to the fact that some packages are contained by multiple jars of the library (not compatible with modules). You will have to wait for Groovy 4 for a compatible version.
I discovered that the JavaFX plugin use this plugin internally. This plugin seems to consider that all dependencies are modules (it is not the default Gradle behaviour).
To make your application works, it seems that you have to:
force Gradle to put Groovy in the classpath instead of the modulepath (it will not be considerered as a module, but seems impossible if you use the javafx plugin)
use the "patch-module" system: it allows Gradle to make a fusion of the library jars into a single module, to prevent the problem of packages that are in different jars
I searched the Groovy jars with IDEA (Project structure/Libraries), and I tried to use the syntax offered by the plugin to use "patch-module":
patchModules.config = [
"org.codehaus.groovy=groovy-ant-3.0.1.jar",
"org.codehaus.groovy=groovy-cli-picocli-3.0.1.jar",
"org.codehaus.groovy=groovy-console-3.0.1.jar",
"org.codehaus.groovy=groovy-datetime-3.0.1.jar",
"org.codehaus.groovy=groovy-docgenerator-3.0.1.jar",
"org.codehaus.groovy=groovy-groovydoc-3.0.1.jar",
"org.codehaus.groovy=groovy-groovysh-3.0.1.jar",
"org.codehaus.groovy=groovy-jmx-3.0.1.jar",
"org.codehaus.groovy=groovy-json-3.0.1.jar",
"org.codehaus.groovy=groovy-jsr-3.0.1.jar",
"org.codehaus.groovy=groovy-macro-3.0.1.jar",
"org.codehaus.groovy=groovy-nio-3.0.1.jar",
"org.codehaus.groovy=groovy-servlet-3.0.1.jar",
"org.codehaus.groovy=groovy-sql-3.0.1.jar",
"org.codehaus.groovy=groovy-swing-3.0.1.jar",
"org.codehaus.groovy=groovy-templates-3.0.1.jar",
"org.codehaus.groovy=groovy-test-junit-3.0.1.jar",
"org.codehaus.groovy=groovy-test-3.0.1.jar",
"org.codehaus.groovy=groovy-testng-3.0.1.jar",
"org.codehaus.groovy=groovy-xml-3.0.1.jar"
]
It only works with a single line "org.codehaus.groovy=X.jar", but a bug prevents it to work with all of the library jars (Look at this issue on Github).
So you have multiple choices:
Use Java instead of Groovy
Wait for a new Groovy release, or new releases of plugins (modules-plugin, and a version of javafx-plugin that use this one internally)
Use old javafx configuration: dependencies are not module by default, and you have to specify manually in build.gradle that JavaFX dependencies should be considered as a module (check my "obsolete" answer to this question)

Can't find ParameterizedTest and ValueSource

I had done a simple project, trying to understand how ParameterizedTest and ValueSource works.
From the below picture it finds the import path, but it throws an error when I try to run the code:
Also the gradle file:
Here is a link to the entire project.
You need to put junit-jupiter-params in the testCompile source set.
junit-jupiter-params exports types like #ParameterizedTest and #ValueSource that are needed at compile (and run~) time.
See also: Missing org.junit.jupiter.params from JUnit5
Starting with version 5.4.0-M1 JUnit Jupiter provides an aggregator artifact that bundles all available Jupiter-defining artifacts for easy consumption. See https://sormuras.github.io/blog/2018-12-26-junit-jupiter-aggregator.html for details.

Exception in compiling groovy & java using maven

My groovy file contains:
#Grapes([
#Grab('org.codehaus.groovy.modules.http-builder:http-builder:0.7'),
#Grab('org.apache.httpcomponents:httpmime:4.5.1')
])
.......code
I am trying to compile groovy and java code. But I am getting below error:
java.lang.RuntimeException: Transform groovy.grape.GrabAnnotationTransformation#69bda33a cannot be run
This works for me, note that I did change HttpBuilder to v.0.7.1:
#Grapes([
#Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7.1'),
#Grab(group='org.apache.httpcomponents', module='httpmime', version='4.5.1')
])
Likely way too late for you to care, but I saw the same error just now.
I suspect the problem is that the #Grab annotation can't take effect because Maven is controlling the dependencies, or perhaps because Maven is trying to compile both Groovy and Java code, and the class loader created by the #Grab annotation can't influence the Java code.
Upshot is, I suspect you (and I) need to move the dependency out of the Groovy class in question, and put it into the pom.xml file Maven is using.

Gradle build error with Simpleframework

I upload my library module to jcenter and I use this module with my application project.
I try to build my application it returns an error.
I searched this issue and This issue is due to be aware of what simpleframework.
I have to use this library both My library module and application module.
How can I solve this problem?
Gradle error msg is below
trouble processing "javax/xml/stream/events/StartElement.class":
Ill-advised or mistaken usage of a core class (java.* or javax.*) when
not building a core library. This is often due to inadvertently
including a core library file in your application's project, when
using an IDE (such as Eclipse). If you are sure you're not
intentionally defining a core class, then this is the most likely
explanation of what's going on. However, you might actually be trying
to define a class in a core namespace, the source of which you may
have taken, for example, from a non-Android virtual machine project.
This will most assuredly not work. At a minimum, it jeopardizes the
compatibility of your app with future versions of the platform. It is
also often of questionable legality. If you really intend to build a
core library -- which is only appropriate as part of creating a full
virtual machine distribution, as opposed to compiling an application
-- then use the "--core-library" option to suppress this error message. If you go ahead and use "--core-library" but are in fact
building an application, then be forewarned that your application will
still fail to build or run, at some point. Please be prepared for
angry customers who find, for example, that your application ceases to
function once they upgrade their operating system. You will be to
blame for this problem. If you are legitimately using some code that
happens to be in a core package, then the easiest safe alternative you
have is to repackage that code. That is, move the classes in question
into your own package namespace. This means that they will never be in
conflict with core system classes. JarJar is a tool that may help you
in this endeavor. If you find that you cannot do this, then that is an
indication that the path you are on will ultimately lead to pain,
suffering, grief, and lamentation. 1 error; aborting Error:Execution
failed for task ':app:preDexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command
'C:\jdk1.7.0\bin\java.exe'' finished with non-zero exit value 1
My library build.gradle dependencies are below.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.mcxiaoke.volley:library:1.0.+'
compile 'com.google.code.gson:gson:2.2.4'
compile ('org.simpleframework:simple-xml:2.7.+') {
exclude module: 'stax'
exclude module: 'stax-api'
exclude module: 'xpp3'
}
}
My Application dependencies are below :
dependencies {
compile 'com.android.support:support-v4:19.+'
compile 'com.google.android.gms:play-services:5.+'
compile 'com.jakewharton:butterknife:5.1.2'
compile 'com.jakewharton.timber:timber:3.1.0'
compile 'commons-io:commons-io:2.4'
compile 'commons-net:commons-net:3.3'
compile 'org.apache.httpcomponents:httpmime:4.2.5'
/*compile 'com.mcxiaoke.volley:library:1.0.+'
compile 'com.google.code.gson:gson:2.2.4'
compile('org.simpleframework:simple-xml:2.7.+') {
exclude module: 'stax'
exclude module: 'stax-api'
exclude module: 'xpp3'
}*/
compile 'org.jsoup:jsoup:1.7.2+'
compile 'com.effectivelife:cokcok-support:1.0.0'
}
I solved this problem.
I add a configurations to my application project.
So my application build.gradle file is below.
configurations {
compile.exclude module: 'stax'
compile.exclude module: 'stax-api'
compile.exclude module: 'xpp3'
}
dependencies {
compile 'com.android.support:support-v4:19.+'
compile 'com.google.android.gms:play-services:5.+'
compile 'com.jakewharton:butterknife:5.1.2'
compile 'com.jakewharton.timber:timber:3.1.0'
compile 'commons-io:commons-io:2.4'
compile 'commons-net:commons-net:3.3'
compile 'org.apache.httpcomponents:httpmime:4.2.5'
compile 'org.jsoup:jsoup:1.7.2+'
compile 'com.effectivelife:cokcok-support:1.0.1'
}

Generated class by protoc generates compile errors

I created a simple .proto file and executed the compiler (protoc-2.5.0rc1-win32.zip). A java file was generated to the prescribed package. However, the generated file does not compile.
The .proto file is simple with a single message with a bunch of simple types optional fields (properly numbered).
The .java file does not compile, for example:
The constructor GeneratedMessage.FieldAccessorTable(Descriptors.Descriptor, String[]) is undefined
The method ensureFieldAccessorsInitialized(Class, Class) is undefined for the type GeneratedMessage.FieldAccessorTable
... and host of other errors along the same line (like trying to override a final method in superclass)
errors that hint at some mismatch at the level of the API version?
Any ideas?
Thanks
RESOLVED: found that the version of proto expected by the API I am using is 2.4.1 and I was using latest.
i have solved the same problem.
the answer:
1.show your protoc complier version
e.g.
D:\workspace2\monitor\src\main\resources>protoc --version
libprotoc 2.6.1
2.make the protoc jar coincident with your protoc complier version
e.g.
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>2.6.1</version>
</dependency>
For me, I tracked this down to akka including an older prototype buffer version, and the versions conflicted.
Solution: Check all your libraries for older versions of prototype buffer, it may be included in something you have already.
My guess is that you first need to build a new protocol buf jar ( protobuf-java-2.5.0rc1.jar ) from the source distribution protobuf-2.5.0rc1.zip and make this a local "system" dependency of your maven pom.xml. I also get compile errors if i just produce new java stubs with the new compiler but have the old 2.4.1 jar dependency in my pom. I couldnt find a maven repository which hosts the 2.5.0rc1.jar already built. If you just take the source files from the source distribution , you miss some class files like com.google.protobuf.DescriptorProtos.*.

Resources