Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Error due to older Groovy version

Hi,
I have code in a tGroovy component which requires a more recent version of Groovy than is provided in Talend. Specifically, there is a missing property 'mkp' in the class MarkupBuilder which is loaded from groovy-1.0.jar. I tested the same script in a recent Groovy version, where it works. Then I installed a more recent version of Talend (5.2.2), to find out it uses the same Groovy version. Next I thought about replacing the jar file, however this got me into deeper trouble.
Any advice?
Kind regards,
Yves
Labels (2)
12 Replies
Anonymous
Not applicable
Author

Hi,
There already been an issue about upgrading groovy jars for groovy components on our Jira, our developer is working on it, please monitor the issue.
https://jira.talendforge.org/browse/TDI-24781
Best regards
Sabrina
Anonymous
Not applicable
Author

I've been using Groovy frequently in Talend, so let me share how to upgrade your tGroovy component to use Groovy 2.1.1:
1. first, download and copy the Groovy jars referenced in the 2nd step to this directory:
{workspace}\java\lib
2. then, edit tGroovy_java.xml in this directory:
{TALEND_INSTALL_DIR}\plugins\org.talend.designer.components.localprovider_5.6.2.20150508_1414\components\tGroovy
Change the references hereafter to whatever Groovy version you adapt to:
<CODEGENERATION>
    <IMPORTS>
<IMPORT NAME="Groovy_Module" MODULE="antlr-2.7.6.jar" UrlPath="platform:/plugin/org.talend.libraries.apache.axis2/lib/antlr-2.7.6.jar" REQUIRED="true" />
<IMPORT NAME="Groovy_Module" MODULE="groovy-2.1.1.jar" UrlPath="platform:/plugin/org.talend.libraries.groovy/lib/groovy-2.1.1.jar" REQUIRED="true" />
<IMPORT NAME="Groovy_Module" MODULE="groovy-starter.jar" UrlPath="platform:/plugin/org.talend.libraries.groovy/lib/groovy-starter.jar" REQUIRED="true" />
<IMPORT NAME="Groovy_Module" MODULE="groovy-xmlrpc-0.3.jar" UrlPath="platform:/plugin/org.talend.libraries.groovy/lib/groovy-xmlrpc-0.3.jar" REQUIRED="true" />
<IMPORT NAME="Groovy_Module" MODULE="groovy-xml-2.1.1.jar" UrlPath="platform:/plugin/org.talend.libraries.groovy/lib/groovy-xml-2.1.1.jar" REQUIRED="true" />
<IMPORT NAME="Groovy_Module" MODULE="groovy-sql-2.1.1.jar" UrlPath="platform:/plugin/org.talend.libraries.groovy/lib/groovy-sql-2.1.1.jar" REQUIRED="true" />
<IMPORT NAME="Groovy_Module" MODULE="asm-4.0.jar" UrlPath="platform:/plugin/org.talend.libraries.groovy/lib/asm-4.0.jar" REQUIRED="true" />
<IMPORT NAME="Groovy_Module" MODULE="asm-analysis-4.0.jar" UrlPath="platform:/plugin/org.talend.libraries.groovy/lib/asm-analysis-4.0.jar" REQUIRED="true" />
<IMPORT NAME="Groovy_Module" MODULE="asm-commons-4.0.jar" UrlPath="platform:/plugin/org.talend.libraries.groovy/lib/asm-commons-4.0.jar" REQUIRED="true" />
<IMPORT NAME="Groovy_Module" MODULE="asm-tree-4.0.jar" UrlPath="platform:/plugin/org.talend.libraries.groovy/lib/asm-tree-4.0.jar" REQUIRED="true" />
<IMPORT NAME="Groovy_Module" MODULE="asm-util-4.0.jar" UrlPath="platform:/plugin/org.talend.libraries.groovy/lib/asm-util-4.0.jar" REQUIRED="true" />
     </IMPORTS>
   </CODEGENERATION>
3. This part required a few code changes so it was a bit trickier, but you'll be just fine if you copy the content beneath verbatim in tGroovy_begin.javajet:
<%@ jet 
    imports="
        org.talend.core.model.process.INode 
        org.talend.core.model.process.ElementParameterParser
        org.talend.designer.codegen.config.CodeGeneratorArgument
        java.util.Map
        java.util.List
    "
%>
<%
    CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
    INode node = (INode)codeGenArgument.getArgument();
    String cid = node.getUniqueName();
    String codeStringArray{} = ElementParameterParser.getValue(node, "__CODE__").split("\n");
%>
String code<%=cid%> = "" 
<%for(int i =0 ;i<codeStringArray.length;i++){
    codeStringArray{i} = codeStringArray{i}.replace("\\","\\\\");
    codeStringArray{i} = codeStringArray{i}.replace("\"","\\\"");    
    %>
    + "<%=codeStringArray{i}%>" + "\n"
<%}%>; 
java.io.ByteArrayInputStream is<%=cid%> = new java.io.ByteArrayInputStream(code<%=cid%>.getBytes());
groovy.lang.Binding binding<%=cid%> = new groovy.lang.Binding();
<%
List<Map<String, String>> tableValues =
    (List<Map<String,String>>)ElementParameterParser.getObjectValue(
        node,
        "__VARIABLES__"
    );
    
    for(Map<String, String> tableValue : tableValues) {
                   %>
        binding<%=cid%>.setVariable(<%=tableValue.get("NAME")%>, <%=tableValue.get("VALUE")%>);
<%
}
%>
groovy.lang.GroovyShell shell<%=cid%> = new groovy.lang.GroovyShell(binding<%=cid%>);
shell<%=cid%>.evaluate(code<%=cid%>);
4. Restart Talend
That's it! 
Anonymous
Not applicable
Author

This topic lives on at TDI-33821
Now, there are incompatibilities between the Ancient Groovy 1.0 (Used on TOS DI 6.1.x) and Java 1.8.
If interested, please see the JIRA which has my attached changes to tGroovy to be compatible with Java 1.8 and upgrade Groovy itself.
I believe the right approach to use this is as follows:
* make a custom component out of the modified tGroovy
* Switch jobs to use the revised version
* Talend to integrate the fix and Groovy version upgrade
* Upon that fix being included in the talend release, switch Jobs back over to using the official talend component