Plugint test under gradle leads to NoSuchMethodError: log4j.WriterAppender

Answered

Hi, I was trying to create a simple test but keep getting error:

com.plugin.test.MessageWriterTest > initializationError FAILED
    java.lang.NoSuchMethodError: org.apache.log4j.WriterAppender.<init>(Lorg/apache/log4j/Layout;Ljava/io/Writer;)V

test task in Gradle looks like this:

test {
repositories {
jcenter()
mavenCentral()
mavenLocal()
maven { url 'http://dl.bintray.com/jetbrains/intellij-plugin-service' }
maven { url "https://dl.bintray.com/antlr/maven/" }
}
dependencies {
testRuntime(gradleTestKit())
testCompileOnly(
'junit:junit:4.12'
)
testImplementation(
'org.junit.jupiter:junit-jupiter-api:5.1.0'
)
testRuntimeOnly(
'org.junit.jupiter:junit-jupiter-engine:5.1.0',
'org.junit.vintage:junit-vintage-engine:5.1.0'
)

testCompileClasspath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.51"
// experiments
testCompile files("lib/openapi.jar")
testCompile files("lib/log4j.jar")
testCompile files("lib/netty-all-4.1.10.Final.jar")
testRuntime files("lib/idea.jar")
}
useJUnitPlatform()
testLogging.exceptionFormat = TestExceptionFormat.FULL
}

And the test

package com.plugin.test

import com.intellij.testFramework.LightCodeInsightTestCase
import junit.framework.TestCase
import org.junit.Test

class MessageWriterTest : LightCodeInsightTestCase() {

@Test
fun testWriteChanges() {
TestCase.assertTrue(true)
TestCase.assertTrue(false)
}
}

 

 

 

4 comments
Comment actions Permalink
Official comment

Did you consider using the intellij-gradle plugin instead? http://www.jetbrains.org/intellij/sdk/docs/tutorials/build_system.html

Comment actions Permalink

Well, I'd love to. I tried to run with such plugin but it doesn't work out at all. On configuration stage, I get a fail:

Cannot find builtin plugin CSS for IDE

The script

buildscript {
repositories {
mavenCentral()
maven { url 'http://dl.bintray.com/jetbrains/intellij-plugin-service' }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}"
}
}

plugins {
id "org.jetbrains.intellij" version "0.4.1"
id 'com.palantir.git-version' version "0.11.0"
}

apply plugin: 'idea'
apply plugin: 'org.jetbrains.intellij'
apply plugin: 'java'
apply plugin: 'kotlin'

dependencies {
compile "org.jetbrains.kotlin:kotlin-runtime:$kotlinVersion"
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
}

intellij {
version ideaVersion
updateSinceUntilBuild false
plugins = [
"com.jetbrains.php:${phpPluginVersion}",
'CSS'
]
pluginName 'Component'
}

wrapper {
gradleVersion '5.1'
}

 

0
Comment actions Permalink

Sorry, not everything is working. I realised that I used wrong version as a dependence

https://intellij-support.jetbrains.com/hc/en-us/community/posts/360002521619-Test-plugin-for-PhpStorm

0
Comment actions Permalink

I ran into the same error. In my case the kotlin-dsl plugin caused the error as it adds many libraries to the classpath including gradle-api-<version>.jar

plugins {
`kotlin-dsl`
idea
id("org.jetbrains.intellij") version "0.4.16" // https://github.com/JetBrains/gradle-intellij-plugin
id ("org.jetbrains.kotlin.jvm") version "1.3.31"
}

After removing kotlin-dsl the error was gone.

References:

 

0

Please sign in to leave a comment.