Jenkins插件无法使用java8进行编译,因为无法识别流类

时间:2017-09-01 09:27:28

标签: java maven jenkins

我正在尝试使用mvn install -Dmaven.test.skip=true构建一个Jenkins插件,但它失败并出现以下错误:

[INFO] --- animal-sniffer-maven-plugin:1.15:check (check) @ osf-builder-suite-for-sfcc-deploy ---
[INFO] Resolved signature org.codehaus.mojo.signature:java17 version as 1.0 from dependencyManagement
[INFO] Checking unresolved references to org.codehaus.mojo.signature:java17:1.0
[ERROR] .../DeployBuilder.java:588: Undefined reference: java.util.stream.Stream java.util.List.stream()
[ERROR] .../DeployBuilder.java:589: Undefined reference: java.util.stream.Stream java.util.stream.Stream.map(java.util.function.Function)
[ERROR] .../DeployBuilder.java:590: Undefined reference: java.util.stream.Stream java.util.stream.Stream.filter(java.util.function.Predicate)
[ERROR] .../DeployBuilder.java:591: Undefined reference: java.util.stream.Stream java.util.stream.Stream.map(java.util.function.Function)
[ERROR] .../DeployBuilder.java:592: Undefined reference: java.util.stream.Collector java.util.stream.Collectors.toList()
[ERROR] .../DeployBuilder.java:592: Undefined reference: Object java.util.stream.Stream.collect(java.util.stream.Collector)
[ERROR] .../DeployBuilder.java:609: Undefined reference: java.util.stream.Stream java.util.List.stream()
[ERROR] .../DeployBuilder.java:609: Undefined reference: boolean java.util.stream.Stream.anyMatch(java.util.function.Predicate)

我已经在我的pom中将java level设置为8。

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>${jdk.version}</source>
                <target>${jdk.version}</target>
                <optimize>true</optimize>
            </configuration>
        </plugin>

任何想法为什么它仍然试图验证/编译为java7和流类不被识别?

我能做些什么才能让它发挥作用?

LE

mvn --version                                                                                                                           ⏎ master ✱ ◼
Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-03T22:39:06+03:00)
Maven home: /usr/local/Cellar/maven/3.5.0/libexec
Java version: 1.8.0_101, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: US-ASCII
OS name: "mac os x", version: "10.12.6", arch: "x86_64", family: "mac"


java -version                                                                                                                             master ✱ ◼
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)


javac -version                                                                                                                            master ✱ ◼
javac 1.8.0_101

mvn tree

[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] ... 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:3.0.0:tree (default-cli) @ my-plugin-deploy ---
[INFO] org.jenkins-ci.plugins:my-plugin-deploy:hpi:1.0-SNAPSHOT
[INFO] +- org.jenkins-ci.plugins:structs:jar:1.9:compile
[INFO] |  \- org.jenkins-ci:symbol-annotation:jar:1.9:compile
[INFO] +- org.jenkins-ci.plugins:credentials:jar:2.1.14:compile
[INFO] |  \- org.antlr:antlr4-runtime:jar:4.5:compile
[INFO] |     \- org.abego.treelayout:org.abego.treelayout.core:jar:1.0.1:compile
[INFO] +- org.jenkins-ci.plugins:token-macro:jar:2.1:compile
[INFO] |  \- org.parboiled:parboiled-java:jar:1.1.7:compile
[INFO] |     +- org.parboiled:parboiled-core:jar:1.1.7:compile
[INFO] |     +- org.ow2.asm:asm:jar:5.0.3:compile
[INFO] |     +- org.ow2.asm:asm-tree:jar:5.0.3:compile
[INFO] |     +- org.ow2.asm:asm-analysis:jar:5.0.3:compile
[INFO] |     \- org.ow2.asm:asm-util:jar:5.0.3:compile
[INFO] +- org.apache.commons:commons-lang3:jar:3.6:compile
[INFO] +- org.apache.commons:commons-text:jar:1.1:compile
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.5.3:compile
[INFO] |  +- org.apache.httpcomponents:httpcore:jar:4.4.6:compile
[INFO] |  +- commons-logging:commons-logging:jar:1.1.3:provided
[INFO] |  \- commons-codec:commons-codec:jar:1.9:compile
[INFO] +- org.zeroturnaround:zt-zip:jar:1.12:compile
[INFO] +- org.bouncycastle:bcprov-jdk15on:jar:1.58:compile
[INFO] +- org.bouncycastle:bcpkix-jdk15on:jar:1.58:compile
[INFO] +- org.codehaus.plexus:plexus-utils:jar:3.1.0:compile
[INFO] +- org.codehaus.mojo.signature:java18:pom:1.0:compile
[INFO] +- com.google.code.findbugs:annotations:jar:3.0.0:provided (optional) 
[INFO] +- net.jcip:jcip-annotations:jar:1.0:provided (optional) 
[INFO] +- org.codehaus.mojo:animal-sniffer-annotations:jar:1.14:provided (optional) 
[INFO] +- javax.servlet:javax.servlet-api:jar:3.1.0:test
[INFO] +- javax.servlet:servlet-api:jar:2.4:provided
[INFO] +- org.jenkins-ci.main:jenkins-core:jar:2.32:provided
[INFO] |  +- org.jenkins-ci.plugins.icon-shim:icon-set:jar:1.0.5:provided
[INFO] |  +- org.jenkins-ci.main:remoting:jar:3.2:provided
[INFO] |  |  \- org.jenkins-ci:constant-pool-scanner:jar:1.2:provided
[INFO] |  +- org.jenkins-ci.main:cli:jar:2.32:provided
[INFO] |  +- org.jenkins-ci:version-number:jar:1.1:provided
[INFO] |  +- org.jenkins-ci:crypto-util:jar:1.1:provided
[INFO] |  +- org.jvnet.hudson:jtidy:jar:4aug2000r7-dev-hudson-1:provided
[INFO] |  +- com.google.inject:guice:jar:4.0:provided
[INFO] |  |  +- javax.inject:javax.inject:jar:1:provided
[INFO] |  |  \- aopalliance:aopalliance:jar:1.0:provided
[INFO] |  +- org.jruby.ext.posix:jna-posix:jar:1.0.3-jenkins-1:provided
[INFO] |  +- com.github.jnr:jnr-posix:jar:3.0.1:provided
[INFO] |  |  +- com.github.jnr:jnr-ffi:jar:1.0.7:provided
[INFO] |  |  |  +- com.github.jnr:jffi:jar:1.2.7:provided
[INFO] |  |  |  +- com.github.jnr:jffi:jar:native:1.2.7:provided
[INFO] |  |  |  +- org.ow2.asm:asm-commons:jar:4.0:provided
[INFO] |  |  |  \- com.github.jnr:jnr-x86asm:jar:1.0.2:provided
[INFO] |  |  \- com.github.jnr:jnr-constants:jar:0.8.5:provided
[INFO] |  +- org.kohsuke:trilead-putty-extension:jar:1.2:provided
[INFO] |  +- org.jenkins-ci:trilead-ssh2:jar:build217-jenkins-8:provided
[INFO] |  +- org.kohsuke.stapler:stapler-groovy:jar:1.248:provided
[INFO] |  |  \- org.kohsuke.stapler:stapler-jelly:jar:1.248:provided
[INFO] |  |     +- org.jenkins-ci:commons-jelly:jar:1.1-jenkins-20120928:provided
[INFO] |  |     \- org.jenkins-ci.dom4j:dom4j:jar:1.6.1-jenkins-4:provided
[INFO] |  +- org.kohsuke.stapler:stapler-jrebel:jar:1.248:provided
[INFO] |  |  \- org.kohsuke.stapler:stapler:jar:1.248:provided
[INFO] |  |     +- javax.annotation:javax.annotation-api:jar:1.2:provided
[INFO] |  |     +- commons-discovery:commons-discovery:jar:0.4:provided
[INFO] |  |     \- org.jvnet:tiger-types:jar:2.2:provided
[INFO] |  +- org.kohsuke:windows-package-checker:jar:1.2:provided
[INFO] |  +- org.kohsuke.stapler:stapler-adjunct-zeroclipboard:jar:1.3.5-1:provided
[INFO] |  +- org.kohsuke.stapler:stapler-adjunct-timeline:jar:1.4:provided
[INFO] |  +- org.kohsuke.stapler:stapler-adjunct-codemirror:jar:1.3:provided
[INFO] |  +- com.infradna.tool:bridge-method-annotation:jar:1.13:provided
[INFO] |  +- org.kohsuke.stapler:json-lib:jar:2.4-jenkins-2:provided
[INFO] |  |  \- net.sf.ezmorph:ezmorph:jar:1.0.6:provided
[INFO] |  +- commons-httpclient:commons-httpclient:jar:3.1:provided
[INFO] |  +- args4j:args4j:jar:2.0.31:provided
[INFO] |  +- org.jenkins-ci:annotation-indexer:jar:1.11:compile
[INFO] |  +- org.jenkins-ci:bytecode-compatibility-transformer:jar:1.8:provided
[INFO] |  |  \- org.kohsuke:asm5:jar:5.0.1:provided
[INFO] |  +- org.jenkins-ci:task-reactor:jar:1.4:provided
[INFO] |  +- org.jvnet.localizer:localizer:jar:1.23:provided
[INFO] |  +- antlr:antlr:jar:2.7.6:provided
[INFO] |  +- org.jvnet.hudson:xstream:jar:1.4.7-jenkins-1:provided
[INFO] |  +- jfree:jfreechart:jar:1.0.9:provided
[INFO] |  |  \- jfree:jcommon:jar:1.0.12:provided
[INFO] |  +- org.apache.ant:ant:jar:1.8.4:provided
[INFO] |  |  \- org.apache.ant:ant-launcher:jar:1.8.4:provided
[INFO] |  +- commons-io:commons-io:jar:2.4:provided
[INFO] |  +- commons-lang:commons-lang:jar:2.6:provided
[INFO] |  +- commons-digester:commons-digester:jar:2.1:provided
[INFO] |  +- commons-beanutils:commons-beanutils:jar:1.8.3:provided
[INFO] |  +- org.apache.commons:commons-compress:jar:1.10:provided
[INFO] |  +- javax.mail:mail:jar:1.4.4:provided
[INFO] |  +- org.jvnet.hudson:activation:jar:1.1.1-hudson-1:provided
[INFO] |  +- jaxen:jaxen:jar:1.1-beta-11:provided
[INFO] |  +- commons-jelly:commons-jelly-tags-fmt:jar:1.0:provided
[INFO] |  +- commons-jelly:commons-jelly-tags-xml:jar:1.1:provided
[INFO] |  +- org.jvnet.hudson:commons-jelly-tags-define:jar:1.0.1-hudson-20071021:provided
[INFO] |  +- org.jenkins-ci:commons-jexl:jar:1.1-jenkins-20111212:provided
[INFO] |  +- org.acegisecurity:acegi-security:jar:1.0.7:provided
[INFO] |  |  +- org.springframework:spring-jdbc:jar:1.2.9:provided
[INFO] |  |  |  \- org.springframework:spring-dao:jar:1.2.9:provided
[INFO] |  |  +- oro:oro:jar:2.0.8:provided
[INFO] |  |  \- log4j:log4j:jar:1.2.17:provided
[INFO] |  +- org.codehaus.groovy:groovy-all:jar:2.4.7:provided
[INFO] |  +- jline:jline:jar:2.12:provided
[INFO] |  +- org.fusesource.jansi:jansi:jar:1.11:provided
[INFO] |  +- org.springframework:spring-webmvc:jar:2.5.6.SEC03:provided
[INFO] |  |  +- org.springframework:spring-beans:jar:2.5.6.SEC03:provided
[INFO] |  |  +- org.springframework:spring-context:jar:2.5.6.SEC03:provided
[INFO] |  |  +- org.springframework:spring-context-support:jar:2.5.6.SEC03:provided
[INFO] |  |  \- org.springframework:spring-web:jar:2.5.6.SEC03:provided
[INFO] |  +- org.springframework:spring-core:jar:2.5.6.SEC03:provided
[INFO] |  +- org.springframework:spring-aop:jar:2.5.6.SEC03:provided
[INFO] |  +- xpp3:xpp3:jar:1.1.4c:provided
[INFO] |  +- javax.servlet:jstl:jar:1.1.0:provided
[INFO] |  +- com.sun.xml.txw2:txw2:jar:20110809:provided
[INFO] |  |  +- javax.xml.stream:stax-api:jar:1.0-2:provided
[INFO] |  |  \- relaxngDatatype:relaxngDatatype:jar:20020414:provided
[INFO] |  +- commons-collections:commons-collections:jar:3.2.1:provided
[INFO] |  +- org.jvnet.winp:winp:jar:1.22:provided
[INFO] |  +- org.jenkins-ci:memory-monitor:jar:1.9:provided
[INFO] |  +- org.codehaus.woodstox:wstx-asl:jar:3.2.9:provided
[INFO] |  |  \- stax:stax-api:jar:1.0.1:provided
[INFO] |  +- org.jenkins-ci:jmdns:jar:3.4.0-jenkins-3:provided
[INFO] |  +- net.java.dev.jna:jna:jar:4.2.1:provided
[INFO] |  +- org.kohsuke:akuma:jar:1.10:provided
[INFO] |  +- org.kohsuke:libpam4j:jar:1.8:provided
[INFO] |  +- org.jvnet.libzfs:libzfs:jar:0.5:provided
[INFO] |  +- com.sun.solaris:embedded_su4j:jar:1.1:provided
[INFO] |  +- net.java.sezpoz:sezpoz:jar:1.12:provided
[INFO] |  +- org.kohsuke.jinterop:j-interop:jar:2.0.6-kohsuke-1:provided
[INFO] |  |  \- org.kohsuke.jinterop:j-interopdeps:jar:2.0.6-kohsuke-1:provided
[INFO] |  |     \- org.samba.jcifs:jcifs:jar:1.2.19:provided
[INFO] |  +- org.jvnet.robust-http-client:robust-http-client:jar:1.2:provided
[INFO] |  +- org.kohsuke:access-modifier-annotation:jar:1.4:provided
[INFO] |  +- commons-fileupload:commons-fileupload:jar:1.3.1-jenkins-1:provided
[INFO] |  +- org.mindrot:jbcrypt:jar:0.3m:provided
[INFO] |  +- com.google.guava:guava:jar:11.0.1:provided
[INFO] |  |  \- com.google.code.findbugs:jsr305:jar:1.3.9:provided
[INFO] |  \- com.jcraft:jzlib:jar:1.1.3-kohsuke-1:provided
[INFO] +- org.jenkins-ci.main:jenkins-war:executable-war:2.32:test
[INFO] |  +- org.jenkins-ci.modules:instance-identity:jar:2.1:test
[INFO] |  |  \- io.github.stephenc.crypto:self-signed-cert-generator:jar:1.0.0:test
[INFO] |  +- org.jenkins-ci.modules:ssh-cli-auth:jar:1.2:test
[INFO] |  +- org.jenkins-ci.modules:slave-installer:jar:1.5:test
[INFO] |  +- org.jenkins-ci.modules:windows-slave-installer:jar:1.6:test
[INFO] |  +- org.jenkins-ci.modules:launchd-slave-installer:jar:1.2:test
[INFO] |  +- org.jenkins-ci.modules:upstart-slave-installer:jar:1.1:test
[INFO] |  +- org.jenkins-ci.modules:systemd-slave-installer:jar:1.1:test
[INFO] |  +- org.jenkins-ci.modules:sshd:jar:1.7:test
[INFO] |  |  \- org.apache.sshd:sshd-core:jar:0.8.0:test
[INFO] |  |     \- org.apache.mina:mina-core:jar:2.0.5:test
[INFO] |  +- org.jenkins-ci.ui:jquery-detached:jar:core-assets:1.2.1:test
[INFO] |  +- org.jenkins-ci.ui:bootstrap:jar:core-assets:1.3.2:test
[INFO] |  |  \- org.jenkins-ci.ui:jquery-detached:jar:1.2:test
[INFO] |  \- org.jenkins-ci.ui:handlebars:jar:core-assets:1.1.1:test
[INFO] +- org.jenkins-ci.main:jenkins-test-harness:jar:2.23:test
[INFO] |  +- org.eclipse.jetty:jetty-webapp:jar:9.2.15.v20160210:test
[INFO] |  |  +- org.eclipse.jetty:jetty-xml:jar:9.2.15.v20160210:test
[INFO] |  |  |  \- org.eclipse.jetty:jetty-util:jar:9.2.15.v20160210:test
[INFO] |  |  \- org.eclipse.jetty:jetty-servlet:jar:9.2.15.v20160210:test
[INFO] |  +- org.eclipse.jetty:jetty-security:jar:9.2.15.v20160210:test
[INFO] |  |  \- org.eclipse.jetty:jetty-server:jar:9.2.15.v20160210:test
[INFO] |  |     +- org.eclipse.jetty:jetty-http:jar:9.2.15.v20160210:test
[INFO] |  |     \- org.eclipse.jetty:jetty-io:jar:9.2.15.v20160210:test
[INFO] |  +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] |  +- org.jenkins-ci.main:jenkins-test-harness-htmlunit:jar:2.18-1:test
[INFO] |  |  +- xalan:xalan:jar:2.7.2:test
[INFO] |  |  +- xalan:serializer:jar:2.7.2:test
[INFO] |  |  +- xerces:xercesImpl:jar:2.11.0:test
[INFO] |  |  +- xml-apis:xml-apis:jar:1.4.01:test
[INFO] |  |  +- net.sourceforge.nekohtml:nekohtml:jar:1.9.22:test
[INFO] |  |  +- net.sourceforge.cssparser:cssparser:jar:0.9.16:test
[INFO] |  |  +- org.w3c.css:sac:jar:1.3:test
[INFO] |  |  +- org.eclipse.jetty.websocket:websocket-client:jar:9.2.12.v20150709:test
[INFO] |  |  +- org.eclipse.jetty.websocket:websocket-common:jar:9.2.12.v20150709:test
[INFO] |  |  \- org.eclipse.jetty.websocket:websocket-api:jar:9.2.12.v20150709:test
[INFO] |  +- org.jvnet.hudson:embedded-rhino-debugger:jar:1.2:test
[INFO] |  +- org.netbeans.modules:org-netbeans-insane:jar:RELEASE72:test
[INFO] |  \- com.github.stephenc.findbugs:findbugs-annotations:jar:1.3.9-1:test
[INFO] +- org.jenkins-ci:test-annotations:jar:1.2:test
[INFO] +- junit:junit:jar:4.12:test
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- org.slf4j:slf4j-api:jar:1.7.7:compile (optional) 
[INFO] +- org.slf4j:log4j-over-slf4j:jar:1.7.7:test
[INFO] +- org.slf4j:jcl-over-slf4j:jar:1.7.7:test
[INFO] \- org.slf4j:slf4j-jdk14:jar:1.7.7:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.304 s
[INFO] Finished at: 2017-09-01T13:24:01+03:00
[INFO] Final Memory: 29M/348M
[INFO] ------------------------------------------------------------------------

1 个答案:

答案 0 :(得分:3)

您必须将嗅探器的签名设置为java 1.8

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>animal-sniffer-maven-plugin</artifactId>
    <version>1.16</version>
    ...
    <configuration>
      ...
      <signature>
        <groupId>org.codehaus.mojo.signature</groupId>
        <artifactId>java18</artifactId>
        <version>1.0</version>
      </signature>
      ...
    </configuration>
    ...
  </plugin>

因此,如果我有<artifactId>java17</artifactId>的签名并且我在其中一个类中使用了流,则嗅探器会抱怨Streams不属于java 1.7

$ mvn animal-sniffer:check
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building test 2
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- animal-sniffer-maven-plugin:1.15:check (default-cli) @ test ---
[INFO] Checking unresolved references to org.codehaus.mojo.signature:java17:1.0
[ERROR] C:\Users\....\Documents\sources\untitled\src\main\java\org\lab\Application.java:15: Undefined reference: java.util.stream.Stream java.util.Arrays.stream(Object[])

如果我将签名更改为<artifactId>java18</artifactId>,嗅探器将不再抱怨:

$ mvn animal-sniffer:check
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building test 2
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- animal-sniffer-maven-plugin:1.15:check (default-cli) @ test ---
[INFO] Checking unresolved references to org.codehaus.mojo.signature:java18:1.0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.244 s
[INFO] Finished at: 2017-09-01T13:01:33+02:00
[INFO] Final Memory: 35M/476M
[INFO] ------------------------------------------------------------------------