سؤال

I'm trying to write a Jenkins plugin and i was in need of some methods from commons-io that were not available. I am using IntelliJ IDEA and when trying to use FileUtils.listFilesAndDirs i was getting error message that the method does not exist. Then I've added the following into my pom.xml file.

    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.4</version>
    </dependency>

After this i could use the above method and others that were not available before. The plugin compiles without errors or warnings but when i run in in Jenkins i get exception that the motioned is not found:

org.apache.commons.io.FileUtils.listFilesAndDirs(Ljava/io/File;Lorg/apache/commons/io/filefilter/IOFileFilter;Lorg/apache/commons/io/filefilter/IOFileFilter;)Ljava/util/Collection;
java.lang.NoSuchMethodError: org.apache.commons.io.FileUtils.listFilesAndDirs(Ljava/io/File;Lorg/apache/commons/io/filefilter/IOFileFilter;Lorg/apache/commons/io/filefilter/IOFileFilter;)Ljava/util/Collection;
    at org.jenkinsci.plugins.my_builder.MyBuilder$1.invoke(MyBuilder.java:118)
    at org.jenkinsci.plugins.my_builder.MyBuilder$1.invoke(MyBuilder.java:60)
    at hudson.FilePath.act(FilePath.java:912)
    at hudson.FilePath.act(FilePath.java:885)
    at org.jenkinsci.plugins.my_builder.MyBuilder.perform(DemandwareBuilder.java:60)
    at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:781)
    at hudson.model.Build$BuildExecution.build(Build.java:199)
    at hudson.model.Build$BuildExecution.doRun(Build.java:160)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:562)
    at hudson.model.Run.execute(Run.java:1665)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:230)

Why does this fail if I've added the dependency to 2.4 version of commons-io? And is there a way to use this more recent version of commons-io for my Jenkins plugin so i can use those methods?

هل كانت مفيدة؟

المحلول

If anyone else also has this issue I've got an answer on jenkins Google group. All that needs to be done is change the class loader policy. See https://wiki.jenkins-ci.org/display/JENKINS/Plugin+Structure#PluginStructure-Classloader

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top