Compilation failure when adding Job DSL plugin as optional dependency

48 views
Skip to first unread message

Dmitry Savenko

unread,
Jul 8, 2015, 9:27:35 AM7/8/15
to job-dsl...@googlegroups.com
Hi everyone,

When I add Job DSL plugin as an optional dependency to my plugin, my plugin stops compiling. Steps to reproduce:

1. Create a new plugin (via mvn -U org.jenkins-ci.tools:maven-hpi-plugin:create)
2. Set parent version in pom.xml to 1.609.1 (current LTS)
3. In automatically created HelloWorldBuilder class, add this line somewhere (e.g. in perform() method):
     XStream xs = Items.XSTREAM;
4. So far, it compiles. Now, add optional dependency on Job DSL:
    <dependencies>
        <dependency>
            <groupId>org.jenkins-ci.plugins</groupId>
            <artifactId>job-dsl</artifactId>
            <version>1.35</version>
            <optional>true</optional>
        </dependency>
    </dependencies>

Result: 


[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5:compile (default-compile) on project job-dsl-test: Compilation failure

[ERROR] /Users/dsavenko/Downloads/plugin-test/job-dsl-test/src/main/java/org/jenkinsci/plugins/jobdsltest/HelloWorldBuilder.java:[3,31] error: package com.thoughtworks.xstream does not exist


Could anyone help me to fix it? I need Job DSL (extending ContextExtensionPoint), and I need XStream as well (doing some serializing/deserializing manually). 


Best regards,

Dmitry.  

Daniel Spilker

unread,
Jul 9, 2015, 1:52:19 PM7/9/15
to job-dsl...@googlegroups.com
If you are using the XStream library, you need to add that to your POM as dependency. It's not a Job DSL problem.

Daniel

--
You received this message because you are subscribed to the Google Groups "job-dsl-plugin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to job-dsl-plugi...@googlegroups.com.
To post to this group, send email to job-dsl...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/job-dsl-plugin/cc52c3b8-2ac0-49f9-ad84-70d825bf2174%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Keith Collison

unread,
Jan 10, 2017, 4:11:25 PM1/10/17
to job-dsl-plugin
I realize this message is ancient history, but having run into the very same issue, I thought I would provide further information in case anyone else runs into it.

Daniel is right of cour
se -- however, for most plugins the xstream dependency is likely resolved transitively via the upstream "jenkins-core".  And when it is, this dependency is given the scope of "provided".  When depending on the "job-dsl" module (job-dsl-core to be exact), the scope of said dependency is "runtime".  Which means the xstream dependency will no longer be included in the compilation classpath.

I've found adding this dependency stanza (in maven) to my plugin's pom.xml eliminates the error, and is "more correct" (though regrettably its xstream version may fall out of sync with that of jenkins core):

<dependency>
<groupId>org.jvnet.hudson</groupId>
<artifactId>xstream</artifactId>
<version>1.4.7-jenkins-1</version>
<scope>provided</scope>
</dependency>

I do wonder if the job-dsl plugin should maintain this dependency's scope as "provided" -- but I have absolutely no familiarity with the job dsl plugin's code.

In any case, this message may help those who encounter the same compile error.

Thanks!
I'm a big fan of the job-dsl plugin, and will be integrating it into the liquibase-runner soon.

- Keith


Daniel Spilker

unread,
Jan 11, 2017, 4:14:00 AM1/11/17
to job-dsl...@googlegroups.com
Hi Keith,

job-dsl-core is supposed to work as a standalone library, so it has a hard dependency to XStream.

Can you try to exclude the XStream dependency from job-dsl? See https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html#Dependency_Exclusions. You do not need to specify a version when excluding dependencies, so that should become outdated.

But it's still not ideal. Can you open an issue in the Jenkins bug tracker for the job-dsl-plugin component? https://issues.jenkins-ci.org

Daniel

To unsubscribe from this group and stop receiving emails from it, send an email to job-dsl-plugin+unsubscribe@googlegroups.com.
To post to this group, send email to job-dsl-plugin@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/job-dsl-plugin/6aa5849c-d9c3-4460-8204-25f9a833c237%40googlegroups.com.

Keith Collison

unread,
Jan 11, 2017, 2:52:31 PM1/11/17
to job-dsl-plugin
Daniel,

Per your instruction, I have created JENKINS-41001 which describes the behavior.

Yes, I agree, using exclusions is seldom ideal.

Let me know if I may be of further assistance.  Thanks!

- Keith
Reply all
Reply to author
Forward
0 new messages