Pmd-xml: java.lang.IllegalArgumentException: Unknown Language 'xml', supported Languages are java


(Naresh L) #1

Hello Guys,

We are using pmd plugin with gradle to run custom pmd rules on our source code. We are able to run java custom rules without any issue.

Now, we are writing xml custom rules using pmd-xml. But, we are getting below error.
java.lang.IllegalArgumentException: Unknown Language ‘xml’ for ruleXmlRuleDemo, supported Languages are java.

It seems by default gradle supports only java for pmd plugin. Can you please help me out to override this property value in gradle file.

I am also sharing my code. Please check.


build.gradle:-

buildscript {
ext {
//springBootVersion = ‘2.0.0.RELEASE’
}
repositories {
mavenCentral()
}
dependencies {
//classpath(“org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}”)

}

}

apply plugin: ‘java’
apply plugin: ‘eclipse’
apply plugin: ‘pmd’
pmd {
ruleSets = []
sourceSets = [sourceSets.main]
ruleSetFiles = rootProject.files(“src/main/resources/archruleset.xml”)
toolVersion = “6.3.0”
}

group = ‘com.sample’
version = ‘0.0.1-SNAPSHOT’
sourceCompatibility = 1.8

repositories {
mavenCentral()
}

dependencies {
compile group: ‘net.sourceforge.pmd’, name: ‘pmd’, version: ‘6.3.0’
compile group: ‘net.sourceforge.pmd’, name: ‘pmd-java’, version: ‘6.3.0’
compile group: ‘net.sourceforge.pmd’, name: ‘pmd-xml’, version: ‘6.3.0’
}
task(runDebug, dependsOn: ‘classes’, type: JavaExec) {
main = “com.mything.server.HttpServer”
classpath = sourceSets.main.runtimeClasspath
jvmArgs = ["-Xdebug", “-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005”]
}


archruleset.xml:-

<?xml version="1.0" encoding="UTF-8"?>


This ruleset validates xml files

Able to parse Xml file using pmd 3

XmlRuleDemo.java:-

package com.sample.demo.xml;

import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.xml.ast.XmlNode;
import net.sourceforge.pmd.lang.xml.rule.AbstractXmlRule;

public class XmlRuleDemo extends AbstractXmlRule{

@Override
public void visit(XmlNode xmlNode, RuleContext ruleContext){
	 System.out.println(xmlNode.getImage());
	 System.out.println(xmlNode.getAsDocument().getNodeName());
	 System.out.println(xmlNode.getAsDocument().getNodeValue());
	 addViolation(ruleContext, xmlNode);
}

}

Thank you in advance.

Best Regards,
Naresh.