How Do I Configure Buildr to run ScalaTest 2.11? - ruby

I'm using Buildr 1.4.20 (with Ruby 2.0.0 on 64-bit Linux) and trying to use ScalaTest with Scala 2.11.2, but I'm getting the following ClassNotFoundException every time I try to run buildr test.
Running tests in MyProject
ScalaTest "MySimpleTest"
An exception or error caused a run to abort. This may have been caused by a problematic custom reporter.
java.lang.NoClassDefFoundError: scala/xml/MetaData
at org.scalatest.tools.ReporterFactory.createJunitXmlReporter(ReporterFactory.scala:209)
at org.scalatest.tools.ReporterFactory.getReporterFromConfiguration(ReporterFactory.scala:230)
at org.scalatest.tools.ReporterFactory$$anonfun$createReportersFromConfigurations$1.apply(ReporterFactory.scala:242)
at org.scalatest.tools.ReporterFactory$$anonfun$createReportersFromConfigurations$1.apply(ReporterFactory.scala:241)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
at scala.collection.Iterator$class.foreach(Iterator.scala:743)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1177)
at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
at org.scalatest.tools.ReporterConfigurations.foreach(ReporterConfiguration.scala:43)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:245)
at org.scalatest.tools.ReporterConfigurations.map(ReporterConfiguration.scala:43)
at org.scalatest.tools.ReporterFactory.createReportersFromConfigurations(ReporterFactory.scala:241)
at org.scalatest.tools.ReporterFactory.getDispatchReporter(ReporterFactory.scala:245)
at org.scalatest.tools.Runner$.withClassLoaderAndDispatchReporter(Runner.scala:2720)
at org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:1043)
at org.scalatest.tools.Runner$.run(Runner.scala:883)
at org.scalatest.tools.ScalaTestAntTask.execute(ScalaTestAntTask.scala:329)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
Caused by: java.lang.ClassNotFoundException: scala.xml.MetaData
at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1365)
at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1315)
at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1068)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 19 more
Naturally, I thought I could fix this by adding a dependency with scala.xml.MetaData in it, so I added "org.scala-lang.modules:scala-xml_2.11:jar:1.0.2" to my test classpath, but I still get the same error.
I'm sure the class is indeed present in the .jar file:
atg#host:~> zipinfo ~/.m2/repository/org/scala-lang/modules/scala-xml_2.11/1.0.2/scala-xml_2.11-1.0.2.jar | grep MetaData
-rw---- 2.0 fat 1441 bl defN 14-May-20 10:09 scala/xml/MetaData$$anonfun$asAttrMap$1.class
-rw---- 2.0 fat 1312 bl defN 14-May-20 10:09 scala/xml/MetaData$$anonfun$toString$1.class
-rw---- 2.0 fat 1215 bl defN 14-May-20 10:09 scala/xml/MetaData$$anonfun$toString1$1.class
-rw---- 2.0 fat 4197 bl defN 14-May-20 10:09 scala/xml/MetaData$.class
-rw---- 2.0 fat 10489 bl defN 14-May-20 10:09 scala/xml/MetaData.class
... so I can only assume that test.with isn't the right way to add this dependency in a Scala project. Can anyone please offer any advice on how to fix this?
My entire buildfile is as follows:
# enable Scala 2.11.2
Buildr.settings.build['scala.version'] = "2.11.2"
Buildr.settings.build['scala.test'] = 'org.scalatest:scalatest_2.11:jar:2.2.2'
Buildr.settings.build['scala.check'] = 'org.scalacheck:scalacheck_2.11:jar:1.11.6'
require 'buildr/scala'
VERSION_NUMBER = "1.0-SNAPSHOT"
GROUP = "..."
COPYRIGHT = "..."
repositories.remote << "http://repo1.maven.org/maven2"
DEPS_COMPILE = "javax.servlet:javax.servlet-api:jar:3.1.0"
desc "..."
define "MyProject" do
project.version = VERSION_NUMBER
project.group = GROUP
manifest["Implementation-Vendor"] = COPYRIGHT
compile.with DEPS_COMPILE
test.with "org.scala-lang.modules:scala-xml_2.11:jar:1.0.2"
end

Your buildfile is ok, this seems to be a problem with buildr.
As a workaround, you could add the scala-xml in the ant dependencies, like so:
VERSION_NUMBER = "1.0-SNAPSHOT"
GROUP = "..."
COPYRIGHT = "..."
Ant.dependencies << "org.scala-lang.modules:scala-xml_2.11:jar:1.0.2"
You should also issue a bug in the buildr's repository.

Related

Unable to build hello_world cc_grpc_library with bazel 6.0.0

I'm trying to build a hello_world cc_grpc_library using bazel 6.0.0 on Ubuntu 22.04, but I'm unable to do so.
Source tree:
WORKSPACE
MODULE.bazel
BUILD
helloworld.proto
.bazelrc
.bazelversion
My WORKSPACE file is empty. WORKSPACE.bzlmod does not exist.
MODULE.bazel contains:
module(name = "helloworld", version = "1.0")
bazel_dep(name = "grpc", version = "1.47.0", repo_name = "com_github_grpc_grpc")
BUILD contains:
load("#rules_proto//proto:defs.bzl", "proto_library")
load("#com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
load("#com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps")
load("#com_github_grpc_grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library")
grpc_deps()
grpc_extra_deps()
proto_library(
name = "helloworld_proto",
srcs = ["helloworld.proto"],
)
cc_proto_library(
name = "helloworld_cc_proto",
deps = [":helloworld_proto"],
)
cc_grpc_library(
name = "helloworld_cc_grpc",
srcs = [":helloworld_proto"],
grpc_only = True,
deps = [":helloworld_cc_proto"],
)
helloworld.proto is a copy of gRPC's helloworld.proto
When I type bazel build :helloworld_cc_grpc I get the following error and don't know how to solve it:
...external/grpc~1.47.0/bazel/grpc_deps.bzl", line 23, column 11, in grpc_bind_deps
native.bind(
Error: no native function or rule 'bind'
Available attributes: aar_import, action_listener, alias, android_binary, android_device, android_device_script_fixture, android_host_service_fixture, android_instrumentation_test, android_library, android_local_test, android_sdk, android_tools_defaults_jar, apple_cc_toolchain, available_xcodes, cc_binary, cc_host_toolchain_alias, cc_import, cc_libc_top_alias, cc_library, cc_proto_library, cc_shared_library, cc_shared_library_permissions, cc_test, cc_toolchain, cc_toolchain_alias, cc_toolchain_suite, config_feature_flag, config_setting, constraint_setting, constraint_value, environment, existing_rule, existing_rules, exports_files, extra_action, fdo_prefetch_hints, fdo_profile, filegroup, genquery, genrule, glob, j2objc_library, java_binary, java_import, java_library, java_lite_proto_library, java_package_configuration, java_plugin, java_plugins_flag_alias, java_proto_library, java_runtime, java_test, java_toolchain, label_flag, label_setting, objc_import, objc_library, package, package_group, package_name, platform, propeller_optimize, proto_lang_toolchain, proto_library, py_binary, py_library, py_runtime, py_test, repository_name, sh_binary, sh_library, sh_test, subpackages, test_suite, toolchain, toolchain_type, xcode_config, xcode_config_alias, xcode_version
bazel version output:
Bazelisk version: v1.15.0
Build label: 6.0.0
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Mon Dec 19 15:52:35 2022 (1671465155)
Build timestamp: 1671465155
Build timestamp as int: 1671465155
I've also found this gRPC github issue but I'm not sure what to do with it.
How to build gRPC's hello world example using bzlmod to manage external dependencies?
I've tried building it with bazel's cc_grpc_library but that wraps actual dependency (gRPC) into yet another layer as it is visible from the comment on the provided link. Either way it wasn't building but I don't recall actual error.
gRPC doesn't yet support Bazel module so it can break but in your case, it looks weird to call grpc_deps() and grpc_extra_deps() functions in BUILD file because those are expected to be called in WORKSPACE file. If it turns out that module doesn't work yet, you may want to use it without module. Please take a look at this example.

Exception in thread "Thread-21" java.lang.NoSuchFieldError: FAIL_ON_SYMBOL_HASH_OVERFLOW

I wrote java code which connect to ElasticSearch node and save documents in index. I got below error:
Exception in thread "Thread-21" java.lang.NoSuchFieldError:
FAIL_ON_SYMBOL_HASH_OVERFLOW
I use these versions according to below link:
https://www.elastic.co/guide/en/elasticsearch/reference/current/release-notes-7.7.0.html
Upgrade to Jackson 2.10.3 #53523 (issues: #27032, #45225)
Update jackson-databind to 2.8.11.6 #53522 (issue: #45225)
Could anyone help me?
list of libs:
algorithmanimator.jar
annogen-0.1.0.jar
ant-1.7.0.jar
antlr-3.3.jar
antlr-runtime-3.3.jar
appache-commons-jexl-2.1.1.jar
appache-commons-lang.jar
appache-commons-logging-1.2.jar
ArchiveLoggerLib.jar
axiom-api-1.2.7.jar
axiom-dom-1.2.7.jar
axiom-impl-1.2.7.jar
axis2-1.4.jar
backport-util-concurrent-3.1.jar
basex-api.jar
bsh-2.0b4.jar
bson-3.0.4.jar
cloning-1.8.5.jar
commandline.jar
commonplugin.jar
commons-codec-1.11.jar
commons-daemon-1.0.15.jar
commons-httpclient-3.1.jar
commons-io-2.4.jar
commons-lang-2.5.jar
commons-logging-1.2.jar
commons-net-3.1.jar
commons-validator-1.5.1.jar
compiler-0.9.6.jar
connector.jar
DJNativeSwing.jar
drools-clips-5.4.0.Final.jar
drools-compiler-5.4.0.Final.jar
drools-core-5.4.0.Final.jar
drools-decisiontables-5.4.0.Final.jar
drools-jsr94-5.4.0.Final.jar
drools-persistence-jpa-5.4.0.Final.jar
drools-templates-5.4.0.Final.jar
drools-verifier-5.4.0.Final.jar
ecj-3.5.1.jar
elasticsearch-7.7.1.jar
elasticsearch-cli-7.7.1.jar
elasticsearch-core-7.7.1.jar
elasticsearch-geo-7.7.1.jar
elasticsearch-rest-client-7.7.1.jar
elasticsearch-rest-high-level-client-7.7.1.jar
elasticsearch-secure-sm-7.7.1.jar
elasticsearch-x-content-7.7.1.jar
geo2Ip.jar
geronimo-activation_1.1_spec-1.0.1.jar
graphgenerator.jar
graph.jar
graphTea.jar
graphtea-library.jar
graphtea-main.jar
graphTea-Old.jar
graphtea-ui-library.jar
HdrHistogram-2.1.9.jar
hppc-0.8.1.jar
httpasyncclient-4.1.4.jar
httpclient-4.5.11.jar
httpclient-cache-4.5.jar
httpclient-win-4.5.jar
httpcore-4.4.13.jar
httpcore-nio-4.4.10.jar
httpmime-4.5.jar
icu4j-60_2.jar
jackson-core-2.8.11.jar
jackson-dataformat-cbor-2.8.11.jar
jackson-dataformat-smile-2.8.11.jar
jackson-dataformat-yaml-2.8.11.jar
jade4j-0.3.9.jar
Jama-1.0.1.jar
javabuilder.jar
javaee.jar
java-mail-1.4.4.jar
jibx-bind-1.1.5.jar
jibx-run-1.1.5.jar
jna-4.5.1.jar
joda-time-2.10.3.jar
jopt-simple-5.0.2.jar
json-20090211.jar
json-org.jar
json-simple.jar
knowledge-api-5.4.0.Final.jar
knowledge-internal-api-5.4.0.Final.jar
KnowledgeWebServices.jar
lang-mustache-7.5.0.jar
ldapbp-1.0.jar
log4j-1.2.15.jar
log4j-api-2.13.1.jar
log4j-core-2.13.1.jar
lucene-analyzers-common-8.5.2.jar
lucene-backward-codecs-8.3.0.jar
lucene-core-8.5.2.jar
lucene-grouping-8.5.2.jar
lucene-highlighter-8.5.2.jar
lucene-join-8.5.2.jar
lucene-memory-8.5.2.jar
lucene-misc-8.5.2.jar
lucene-queries-8.5.2.jar
lucene-queryparser-8.5.2.jar
lucene-sandbox-8.5.2.jar
lucene-spatial3d-8.5.2.jar
lucene-spatial-8.4.1.jar
lucene-spatial-extras-8.5.2.jar
lucene-suggest-8.5.2.jar
mongodb-driver-3.0.4.jar
mongodb-driver-core-3.0.4.jar
mvel2-2.1.0.drools16.jar
neethi-2.0.4.jar
objenesis-1.2.jar
org.nmap4j-1.1.0-sources.jar
PersianCalender.jar
poi-3.17.jar
poi-contrib-3.2-final.jar
poi-examples-3.17.jar
poi-excelant-3.17.jar
poi-ooxml-3.17.jar
poi-ooxml-schemas-3.17.jar
poi-scratchpad-3.17.jar
postgresql-9.3-1102.jdbc41.jar
Proc.jar
rank-eval-client-7.5.0.jar
reports.jar
SitraManagementKnowledgeBase.aar
SitraSharedJavaLibs.jar
snakeyaml-1.17.jar
stax-api-1.0.1.jar
sun-jndi-ldap.jar
syslog4j-0.9.46-bin.jar
t-digest-3.2.jar
visualization.jar
woden-api-1.0M8.jar
wsdl4j-1.6.2.jar
wstx-asl-3.2.4.jar
xmlbeans-2.3.0.jar
XmlSchema-1.4.2.jar
There are conflict libraries.
You said in your question that you are using jackson-core-2.10.3.jar
And in your dependency list, I see jackson-core-2.10.3.jar
Two different versions causing the conflict. It could probably be transitive dependency. Exclude the one you don't need.
You can refer another similar forum topic
Finally, I found the problem, geo2Ip.jar was old and there was old jackson-core library in it, and there was conflict between jackson-core-2.8.11.jar and jackson-core in geo2Ip.jar.

Overwrite Databricks Dependency

In our project we're using com.typesafe:config in version 1.3.4. According to the latest release notes, this dependency is already provided by Databricks on the cluster, but in a very old version (1.2.1).
How can I overwrite the provided dependency with our own version?
We use maven, in our dependencies I have
<dependency>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
<version>1.3.4</version>
</dependency>
Our created jar file should therefore contain the newer version.
I created a Job by uploading the jar file. The Job fails because it can't find a method that was added after version 1.2.1, so it looks like the library we provided gets overwritten by the older version on the cluster.
In the end we have fixed this by shading the relevant classes, by adding the following to our build.sbt
assemblyShadeRules in assembly := Seq(
ShadeRule.rename("com.typesafe.config.**" -> "shadedSparkConfigForSpark.#1").inAll
)
We solved it in the end by utilizing Sparks ChildFirstURLClassLoader. The project is open source so you can check it out yourself here and the usage of the method here.
But for reference, here is the method in its entirety. You need to provide a Seq of jars that you want to override with your own, in our case it's the typesafe config.
def getChildFirstClassLoader(jars: Seq[String]): ChildFirstURLClassLoader = {
val initialLoader = getClass.getClassLoader.asInstanceOf[URLClassLoader]
#tailrec
def collectUrls(clazz: ClassLoader, acc: Map[String, URL]): Map[String, URL] = {
val urlsAcc: Map[String, URL] = acc++
// add urls on this level to accumulator
clazz.asInstanceOf[URLClassLoader].getURLs
.map( url => (url.getFile.split(Environment.defaultPathSeparator).last, url))
.filter{ case (name, url) => jars.contains(name)}
.toMap
// check if any jars without URL are left
val jarMissing = jars.exists(jar => urlsAcc.get(jar).isEmpty)
// return accumulated if there is no parent left or no jars are missing anymore
if (clazz.getParent == null || !jarMissing) urlsAcc else collectUrls(clazz.getParent, urlsAcc)
}
// search classpath hierarchy until all jars are found or we have reached the top
val urlsMap = collectUrls(initialLoader, Map())
// check if everything found
val jarsNotFound = jars.filter( jar => urlsMap.get(jar).isEmpty)
if (jarsNotFound.nonEmpty) {
logger.info(s"""available jars are ${initialLoader.getURLs.mkString(", ")} (not including parent classpaths)""")
throw ConfigurationException(s"""jars ${jarsNotFound.mkString(", ")} not found in parent class loaders classpath. Cannot initialize ChildFirstURLClassLoader.""")
}
// create child-first classloader
new ChildFirstURLClassLoader(urlsMap.values.toArray, initialLoader)
}
As you can see, it also has some logic to abort if the jar files you specified do not exist in the classpath.
Databricks supports the initialization script (cluster scope or global scope) so that you can install/remove any dependency. The details are at https://docs.databricks.com/clusters/init-scripts.html.
In your initialization script, you can remove the default jar file locates at databricks driver/executor classpath /databricks/jars/ and add the expected one there.

Processing 2.2.1 Video - AbstractMethodError - GStreamer / JNA mismatch?

I am trying to use processing-video 2.2.1 as a library from my (Scala) project. I can run the demo capture sketches directly in the Processing IDE, but from my project I get an error that looks like a version mismatch:
Exception in thread "Animation Thread" java.lang.AbstractMethodError: com.sun.jna.Structure.getFieldOrder()Ljava/util/List;
at com.sun.jna.Structure.fieldOrder(Structure.java:868)
at com.sun.jna.Structure.getFields(Structure.java:894)
at com.sun.jna.Structure.deriveLayout(Structure.java:1042)
at com.sun.jna.Structure.calculateSize(Structure.java:966)
at com.sun.jna.Structure.calculateSize(Structure.java:933)
at com.sun.jna.Structure.allocateMemory(Structure.java:360)
at com.sun.jna.Structure.<init>(Structure.java:184)
at com.sun.jna.Structure.<init>(Structure.java:172)
at com.sun.jna.Structure.<init>(Structure.java:159)
at com.sun.jna.Structure.<init>(Structure.java:151)
at org.gstreamer.lowlevel.GObjectAPI$GTypeInstance.<init>(GObjectAPI.java:114)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at java.lang.Class.newInstance(Class.java:442)
at com.sun.jna.Structure.newInstance(Structure.java:1635)
at com.sun.jna.Structure.newInstance(Structure.java:1621)
at com.sun.jna.Structure.size(Structure.java:950)
at com.sun.jna.Native.getNativeSize(Native.java:1076)
at com.sun.jna.Structure.getNativeSize(Structure.java:1927)
at com.sun.jna.Structure.getNativeSize(Structure.java:1920)
at com.sun.jna.Structure.validateField(Structure.java:1018)
at com.sun.jna.Structure.validateFields(Structure.java:1032)
at com.sun.jna.Structure.<init>(Structure.java:179)
at com.sun.jna.Structure.<init>(Structure.java:172)
at com.sun.jna.Structure.<init>(Structure.java:159)
at com.sun.jna.Structure.<init>(Structure.java:151)
at org.gstreamer.lowlevel.GObjectAPI$GParamSpec.<init>(GObjectAPI.java:395)
at org.gstreamer.GObject.findProperty(GObject.java:656)
at org.gstreamer.GObject.set(GObject.java:87)
at processing.video.Capture.initGStreamer(Unknown Source)
at processing.video.Capture.<init>(Unknown Source)
at (my sketch)
The Maven POM file is here. I end up with the following libraries on the class path:
com.googlecode.gstreamer-java:gstreamer-java:1.5
net.java.dev.jna:jna:4.0.0
net.java.dev.jna:platform:3.4.0
org.processing:core:2.2.1
org.processing:video:2.2.1
My intuition says there is a mismatch between jna and platform - should they have the same version? That would indicate that the published POM is wrong. Which version does the Processing standalone use? Unfortunately the jars there are stripped of version information.
Indeed, it seems the processing POM specifies an incompatible JNA version. In sbt, I could fix this with a dependencyOverrides declaration:
def processingVersion = "2.2.1"
def gstreamerVersion = "1.5"
def jnaVersion = "3.4.0"
libraryDependencies ++= Seq(
"org.processing" % "video" % processingVersion,
"com.googlecode.gstreamer-java" % "gstreamer-java" % gstreamerVersion
)
dependencyOverrides += "net.java.dev.jna" % "jna" % jnaVersion // !
for gradle peeps thats:
implementation ("org.processing:core:3.3.7") {
exclude group: 'net.java.dev.jna'
}
// https://mvnrepository.com/artifact/org.processing/video
implementation ("org.processing:video:3.3.7) {
exclude group: 'net.java.dev.jna'
}
// higher jna versions have abstract Structure.getFieldOrder which gstreamer doesn't implement
implementation "net.java.dev.jna:jna:3.4.0"

Unable to use logback.groovy, but logback.xml works

I wanted to configure Logback using Groovy DSL. The file is very simple:
import ch.qos.logback.classic.encoder.PatternLayoutEncoder
import ch.qos.logback.core.ConsoleAppender
import static ch.qos.logback.classic.Level.DEBUG
import static ch.qos.logback.classic.Level.INFO
appender("stdout", ConsoleAppender) {
encoder(PatternLayoutEncoder) {
pattern = "%d %p [%c] - <%m>%n"
}
}
root(INFO, ["stdout"])
I use Gradle to build my application and run it with jettyRun. I get the following error:
Failed to instantiate [ch.qos.logback.classic.LoggerContext]
Reported exception:
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'ch.qos.logback.core.ConsoleAppender[null]' with class 'ch.qos.logback.core.ConsoleAppender' to class 'ch.qos.logback.core.Appender'
at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:360)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:599)
at ch.qos.logback.classic.gaffer.ConfigurationDelegate.appender(ConfigurationDelegate.groovy:119)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at org.codehaus.groovy.runtime.metaclass.MixinInstanceMetaMethod.invoke(MixinInstanceMetaMethod.java:53)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoMetaMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:308)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:52)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:149)
However, when I switch to equivalent XML configuration, everything works. What am I doing wrong?
Using Logback 1.0.0. Tried with Logback 1.0.3.
I figured the solution out, but some questions remain opened. The problem was that I had no proper Groovy on the classpath. I decided to make an example project to demonstrate this bug. I started with a console application using Gradle's "application" plugin. I didn't include Groovy as dependency.
apply plugin: 'application'
repositories {
mavenCentral()
}
ext.logbackVersion = '1.0.3'
ext.slf4jVersion = '1.6.4'
dependencies {
compile "ch.qos.logback:logback-classic:$ext.logbackVersion"
compile "org.slf4j:jcl-over-slf4j:$ext.slf4jVersion"
//runtime "org.codehaus.groovy:groovy:1.8.6" // the problem was here
}
mainClassName = "org.test.Main"
This gave me an error, which is quite straighforward.
|-ERROR in ch.qos.logback.classic.LoggerContext[default] - Groovy classes are not available on the class path. ABORTING INITIALIZATION.
OK, cool. The dependency was missing - easy to fix. But why didn't I get the same error when I ran my web application? Adding Groovy dependency solved the initial problem in the web application. I stripped my project down and will create a corresponding JIRA. Perhaps, Groovy on classpath detection is not quite correct.
The GroovyCastException "cannot cast ConsoleAppender as Appender" has all the bearings of a class loader issue. Which version of groovy is this? Could you open a bug report including a test case for reproducing this issuew?
colleagues.
I have faced almost the same trouble today:
When I use logback.xml everything works fine
When I use logback.groovy in IntelliJ IDEA eveything works fine too
When I use logback.groovy when start my script from command line I got a lot of errors like
:
D:\Projects\PRDMonitoring\sources>groovy tray.groovy PRD
Failed to instantiate [ch.qos.logback.classic.LoggerContext]
Reported exception:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 2: unable to resolve class ch.qos.logback.classic.filter.LevelFilter
# line 2, column 1.
import ch.qos.logback.classic.filter.LevelFilter
^
Script1.groovy: -1: unable to resolve class ch.qos.logback.classic.encoder.PatternLayoutEncoder
# line -1, column -1.
Script1.groovy: 3: unable to resolve class ch.qos.logback.core.ConsoleAppender
# line 3, column 1.
import ch.qos.logback.core.ConsoleAppender
^
Script1.groovy: -1: unable to resolve class ch.qos.logback.classic.Level
# line -1, column -1.
Script1.groovy: 6: unable to resolve class ch.qos.logback.core.spi.FilterReply
# line 6, column 1.
import static ch.qos.logback.core.spi.FilterReply.ACCEPT
^
Script1.groovy: 7: unable to resolve class ch.qos.logback.core.spi.FilterReply
# line 7, column 1.
import static ch.qos.logback.core.spi.FilterReply.DENY
But after a couple of minutes to find a solution I figured out, that the following string before #Grapes annotation fixes a trouble with classes loading #GrabConfig(systemClassLoader=true)
#GrabConfig(systemClassLoader=true)
#Grapes([
#Grab(group = 'org.codehaus.groovy.modules.http-builder', module = 'http-builder', version = '0.6'),
#Grab(group = 'org.apache.commons', module='commons-lang3', version='3.0'),
#Grab(group = 'commons-io', module = 'commons-io', version = '2.4'),
#Grab(group = 'joda-time', module = 'joda-time', version = '2.9.4'),
#Grab(group = 'ch.qos.logback', module = 'logback-classic', version = '1.1.7'),
#Grab(group = 'ch.qos.logback', module = 'logback-core', version = '1.1.7')
])

Resources