由于需要支持某些功能,修改了presto源码,编译的时候报错,presto代码风格检查比较严格,这里主要说干就干mvn的两个编译依赖问题
问题1:隐式依赖问题排查
[INFO] --- duplicate-finder-maven-plugin:1.2.1:check (default) @ presto-main ---
[INFO] Checking compile classpath
[INFO] Checking runtime classpath
[INFO] Checking test classpath
[WARNING] Found duplicate and different classes in [commons-logging:commons-logging:1.2, org.slf4j:jcl-over-slf4j:1.7.25]:
[WARNING] org.apache.commons.logging.Log
[WARNING] org.apache.commons.logging.LogConfigurationException
[WARNING] org.apache.commons.logging.LogFactory
[WARNING] org.apache.commons.logging.impl.NoOpLog
[WARNING] org.apache.commons.logging.impl.SimpleLog
[WARNING] Found duplicate classes/resources in runtime classpath.
[WARNING] Found duplicate and different classes in [commons-logging:commons-logging:1.2, org.slf4j:jcl-over-slf4j:1.7.25]:
[WARNING] org.apache.commons.logging.Log
[WARNING] org.apache.commons.logging.LogConfigurationException
[WARNING] org.apache.commons.logging.LogFactory
[WARNING] org.apache.commons.logging.impl.NoOpLog
[WARNING] org.apache.commons.logging.impl.SimpleLog
[WARNING] Found duplicate classes/resources in test classpath.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:44 min
[INFO] Finished at: 2020-05-13T15:29:49+08:00
[INFO] Final Memory: 97M/2787M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.basepom.maven:duplicate-finder-maven-plugin:1.2.1:check (default) on project presto-main: Found duplicate classes/resources! -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
看WARNING提示是有依赖冲突了
[WARNING] Found duplicate and different classes in [commons-logging:commons-logging:1.2, org.slf4j:jcl-over-slf4j:1.7.25]:
执行:mvn duplicate-finder:check,也可以看到具体原因。
找出commons-logging:commons-logging:1.2和org.slf4j:jcl-over-slf4j分别是哪里依赖的,找到依赖的地方,将commons-logging或者jcl-over-slf4j排除掉其中一个即可。
执行命令:mvn dependency:tree,查看依赖树。
mvn dependency:tree
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building presto-main 0.224
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.10:tree (default-cli) @ presto-main ---
[INFO] com.facebook.presto:presto-main:jar:0.224
[INFO] +- org.locationtech.jts:jts-core:jar:1.15.0:compile
[INFO] +- com.esri.geometry:esri-geometry-api:jar:2.2.2:compile
[INFO] +- com.facebook.presto:presto-geospatial-toolkit:jar:0.224:compile
[INFO] +- it.unimi.dsi:fastutil:jar:6.5.9:compile
[INFO] +- org.apache.commons:commons-math3:jar:3.6.1:compile
[INFO] +- com.facebook.presto:presto-spi:jar:0.224:compile
[INFO] +- com.facebook.presto:presto-array:jar:0.224:compile
[INFO] +- com.facebook.presto:presto-bytecode:jar:0.224:compile
[INFO] | +- org.ow2.asm:asm-tree:jar:6.2.1:compile
[INFO] | +- org.ow2.asm:asm-util:jar:6.2.1:compile
[INFO] | \- org.ow2.asm:asm-analysis:jar:6.2.1:compile
[INFO] +- com.facebook.presto:presto-client:jar:0.224:compile
[INFO] | +- com.squareup.okhttp3:okhttp:jar:3.9.0:compile
[INFO] | | \- com.squareup.okio:okio:jar:1.13.0:compile
[INFO] | \- com.squareup.okhttp3:okhttp-urlconnection:jar:3.9.0:compile
[INFO] +- com.facebook.presto:presto-parser:jar:0.224:compile
[INFO] | \- org.antlr:antlr4-runtime:jar:4.7.1:compile
[INFO] +- com.facebook.presto:presto-matching:jar:0.224:compile
[INFO] +- com.facebook.presto:presto-memory-context:jar:0.224:compile
[INFO] +- com.google.code.findbugs:jsr305:jar:3.0.2:compile
[INFO] +- io.airlift:bootstrap:jar:0.178:compile
[INFO] +- io.airlift:aircompressor:jar:0.13:compile
[INFO] +- io.airlift:slice:jar:0.36:compile
[INFO] +- io.airlift:concurrent:jar:0.178:compile
[INFO] +- io.airlift:node:jar:0.178:compile
[INFO] +- io.airlift:json:jar:0.178:compile
[INFO] | +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.9.7:compile
[INFO] | +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.9.7:compile
[INFO] | +- com.fasterxml.jackson.datatype:jackson-datatype-guava:jar:2.9.7:compile
[INFO] | +- com.fasterxml.jackson.datatype:jackson-datatype-joda:jar:2.9.7:compile
[INFO] | \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.9.7:compile
[INFO] +- io.airlift:configuration:jar:0.178:compile
[INFO] | \- cglib:cglib-nodep:jar:3.2.5:compile
[INFO] +- io.airlift:discovery:jar:0.178:compile
[INFO] +- io.airlift:event:jar:0.178:compile
[INFO] +- io.airlift:http-server:jar:0.178:compile
[INFO] | +- org.eclipse.jetty:jetty-http:jar:9.4.14.v20181114:compile
[INFO] | +- org.eclipse.jetty:jetty-io:jar:9.4.14.v20181114:compile
[INFO] | +- org.eclipse.jetty.http2:http2-server:jar:9.4.14.v20181114:compile
[INFO] | | \- org.eclipse.jetty.http2:http2-common:jar:9.4.14.v20181114:compile
[INFO] | | \- org.eclipse.jetty.http2:http2-hpack:jar:9.4.14.v20181114:compile
[INFO] | +- org.eclipse.jetty:jetty-server:jar:9.4.14.v20181114:compile
[INFO] | +- org.eclipse.jetty:jetty-util:jar:9.4.14.v20181114:compile
[INFO] | +- org.eclipse.jetty:jetty-servlet:jar:9.4.14.v20181114:compile
[INFO] | +- org.eclipse.jetty:jetty-security:jar:9.4.14.v20181114:compile
[INFO] | +- org.eclipse.jetty:jetty-jmx:jar:9.4.14.v20181114:compile
[INFO] | \- ch.qos.logback:logback-core:jar:1.2.3:compile
[INFO] +- io.airlift:jaxrs:jar:0.178:compile
[INFO] | +- javax.activation:activation:jar:1.1.1:runtime
[INFO] | +- org.glassfish.jersey.core:jersey-common:jar:2.26:compile
[INFO] | | \- org.glassfish.hk2:osgi-resource-locator:jar:1.0.1:compile
[INFO] | +- org.glassfish.jersey.core:jersey-server:jar:2.26:compile
[INFO] | | \- org.glassfish.jersey.media:jersey-media-jaxb:jar:2.26:compile
[INFO] | +- org.glassfish.jersey.containers:jersey-container-servlet-core:jar:2.26:compile
[INFO] | +- org.glassfish.jersey.containers:jersey-container-servlet:jar:2.26:runtime
[INFO] | \- org.glassfish.jersey.inject:jersey-hk2:jar:2.26:runtime
[INFO] | \- org.glassfish.hk2:hk2-locator:jar:2.5.0-b42:runtime
[INFO] | +- org.glassfish.hk2:hk2-api:jar:2.5.0-b42:runtime
[INFO] | +- org.glassfish.hk2:hk2-utils:jar:2.5.0-b42:runtime
[INFO] | \- org.javassist:javassist:jar:3.22.0-GA:runtime
[INFO] +- io.airlift:jmx:jar:0.178:compile
[INFO] | \- com.sun:tools:jar:1.8:system
[INFO] +- io.airlift:jmx-http:jar:0.178:compile
[INFO] +- io.airlift:log:jar:0.178:compile
[INFO] +- io.airlift:log-manager:jar:0.178:compile
[INFO] | +- org.slf4j:slf4j-jdk14:jar:1.7.25:runtime
[INFO] | +- org.slf4j:log4j-over-slf4j:jar:1.7.25:runtime
[INFO] | \- org.slf4j:jcl-over-slf4j:jar:1.7.25:runtime
[INFO] +- io.airlift.resolver:resolver:jar:1.4:compile
[INFO] | +- org.sonatype.aether:aether-spi:jar:1.13.1:compile
[INFO] | +- org.sonatype.aether:aether-impl:jar:1.13.1:compile
[INFO] | +- org.sonatype.aether:aether-util:jar:1.13.1:compile
[INFO] | +- org.sonatype.aether:aether-connector-file:jar:1.13.1:compile
[INFO] | +- org.sonatype.aether:aether-connector-asynchttpclient:jar:1.13.1:compile
[INFO] | | \- com.ning:async-http-client:jar:1.6.5:compile
[INFO] | +- io.netty:netty:jar:3.6.2.Final:runtime
[INFO] | +- org.apache.maven:maven-core:jar:3.0.4:compile
[INFO] | | +- org.apache.maven:maven-settings:jar:3.0.4:compile
[INFO] | | +- org.apache.maven:maven-settings-builder:jar:3.0.4:compile
[INFO] | | +- org.apache.maven:maven-repository-metadata:jar:3.0.4:compile
[INFO] | | +- org.apache.maven:maven-plugin-api:jar:3.0.4:compile
[INFO] | | +- org.apache.maven:maven-model-builder:jar:3.0.4:compile
[INFO] | | +- org.codehaus.plexus:plexus-interpolation:jar:1.14:compile
[INFO] | | +- org.codehaus.plexus:plexus-utils:jar:2.0.6:compile
[INFO] | | +- org.codehaus.plexus:plexus-component-annotations:jar:1.5.5:compile
[INFO] | | \- org.sonatype.plexus:plexus-sec-dispatcher:jar:1.3:compile
[INFO] | +- org.apache.maven:maven-model:jar:3.0.4:compile
[INFO] | +- org.apache.maven:maven-artifact:jar:3.0.4:compile
[INFO] | +- org.apache.maven:maven-aether-provider:jar:3.0.4:compile
[INFO] | +- org.apache.maven:maven-embedder:jar:3.0.4:runtime
[INFO] | | +- org.apache.maven:maven-compat:jar:3.0.4:runtime
[INFO] | | | \- org.apache.maven.wagon:wagon-provider-api:jar:2.2:runtime
[INFO] | | \- org.sonatype.plexus:plexus-cipher:jar:1.7:compile
[INFO] | +- org.codehaus.plexus:plexus-container-default:jar:1.5.5:compile
[INFO] | | \- org.apache.xbean:xbean-reflect:jar:3.4:compile
[INFO] | +- org.codehaus.plexus:plexus-classworlds:jar:2.4:compile
[INFO] | \- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] +- io.airlift:security:jar:0.178:compile
[INFO] +- io.airlift:stats:jar:0.178:compile
[INFO] | \- org.hdrhistogram:HdrHistogram:jar:2.1.9:compile
[INFO] +- io.airlift:trace-token:jar:0.178:compile
[INFO] +- io.airlift:units:jar:1.3:compile
[INFO] +- io.airlift:joni:jar:2.1.5.3:compile
[INFO] +- io.airlift:joda-to-java-time-bridge:jar:3:compile
[INFO] +- com.teradata:re2j-td:jar:1.4:compile
[INFO] +- io.airlift.discovery:discovery-server:jar:1.29:compile
[INFO] | +- io.airlift:jmx-http-rpc:jar:0.159:compile
[INFO] | +- com.google.inject.extensions:guice-multibindings:jar:4.2.0:compile
[INFO] | +- org.iq80.leveldb:leveldb-api:jar:0.10:compile
[INFO] | \- org.iq80.leveldb:leveldb:jar:0.10:compile
[INFO] +- org.openjdk.jol:jol-core:jar:0.2:compile
[INFO] +- javax.servlet:javax.servlet-api:jar:3.1.0:compile
[INFO] +- javax.annotation:javax.annotation-api:jar:1.3.1:compile
[INFO] +- javax.ws.rs:javax.ws.rs-api:jar:2.1:compile
[INFO] +- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.7:compile
[INFO] +- com.fasterxml.jackson.core:jackson-core:jar:2.9.7:compile
[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.9.7:compile
[INFO] +- com.fasterxml.jackson.module:jackson-module-afterburner:jar:2.9.7:compile
[INFO] +- com.fasterxml.jackson.dataformat:jackson-dataformat-smile:jar:2.9.7:compile
[INFO] +- joda-time:joda-time:jar:2.10:compile
[INFO] +- org.weakref:jmxutils:jar:1.19:compile
[INFO] +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] +- javax.inject:javax.inject:jar:1:compile
[INFO] +- com.google.inject:guice:jar:4.2.0:compile
[INFO] | \- aopalliance:aopalliance:jar:1.0:compile
[INFO] +- com.google.guava:guava:jar:24.1-jre:compile
[INFO] | +- org.checkerframework:checker-compat-qual:jar:2.0.0:compile
[INFO] | +- com.google.errorprone:error_prone_annotations:jar:2.1.3:compile
[INFO] | +- com.google.j2objc:j2objc-annotations:jar:1.1:compile
[INFO] | \- org.codehaus.mojo:animal-sniffer-annotations:jar:1.14:compile
[INFO] +- io.airlift:http-client:jar:0.178:compile
[INFO] | +- org.eclipse.jetty:jetty-client:jar:9.4.14.v20181114:compile
[INFO] | +- org.eclipse.jetty.http2:http2-client:jar:9.4.14.v20181114:compile
[INFO] | | \- org.eclipse.jetty:jetty-alpn-client:jar:9.4.14.v20181114:compile
[INFO] | \- org.eclipse.jetty.http2:http2-http-client-transport:jar:9.4.14.v20181114:compile
[INFO] +- org.jetbrains:annotations:jar:13.0:provided
[INFO] +- org.sonatype.aether:aether-api:jar:1.13.1:compile
[INFO] +- org.ow2.asm:asm:jar:6.2.1:compile
[INFO] +- org.jgrapht:jgrapht-core:jar:0.9.0:compile
[INFO] +- org.pcollections:pcollections:jar:2.1.2:compile
[INFO] +- org.apache.lucene:lucene-analyzers-common:jar:7.2.1:compile
[INFO] +- io.jsonwebtoken:jjwt:jar:0.9.0:compile
[INFO] +- org.apache.bval:bval-jsr:jar:1.1.1:compile
[INFO] | +- org.apache.bval:bval-core:jar:1.1.1:compile
[INFO] | | \- commons-beanutils:commons-beanutils-core:jar:1.8.3:compile
[INFO] | +- org.apache.commons:commons-lang3:jar:3.4:compile
[INFO] | +- javax.xml.bind:jaxb-api:jar:2.2.6:compile
[INFO] | \- com.sun.xml.bind:jaxb-impl:jar:2.2.6:compile
[INFO] +- org.testng:testng:jar:6.10:provided
[INFO] | \- com.beust:jcommander:jar:1.48:provided
[INFO] +- io.airlift:testing:jar:0.178:test
[INFO] +- org.assertj:assertj-core:jar:3.8.0:test
[INFO] +- com.h2database:h2:jar:1.4.197:test
[INFO] +- com.facebook.presto:presto-tpch:jar:0.224:test
[INFO] +- com.facebook.presto:presto-parser:test-jar:tests:0.224:test
[INFO] +- com.facebook.presto:presto-spi:test-jar:tests:0.224:test
[INFO] +- org.openjdk.jmh:jmh-core:jar:1.20:test
[INFO] | \- net.sf.jopt-simple:jopt-simple:jar:4.6:test
[INFO] +- org.openjdk.jmh:jmh-generator-annprocess:jar:1.20:test
[INFO] +- io.airlift.tpch:tpch:jar:0.9:test
[INFO] +- io.airlift:jaxrs-testing:jar:0.178:test
[INFO] | +- org.glassfish.jersey.core:jersey-client:jar:2.26:compile
[INFO] | +- org.glassfish.jersey.test-framework:jersey-test-framework-core:jar:2.26:test
[INFO] | \- org.glassfish.jersey.test-framework.providers:jersey-test-framework-provider-inmemory:jar:2.26:test
[INFO] +- com.facebook.presto:presto-plugin-toolkit:jar:0.224:compile
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.5.1:compile
[INFO] | +- commons-logging:commons-logging:jar:1.2:compile
[INFO] | \- commons-codec:commons-codec:jar:1.9:compile
[INFO] +- org.apache.httpcomponents:httpcore:jar:4.4.3:compile
[INFO] \- com.alibaba:fastjson:jar:1.2.45:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.128 s
[INFO] Finished at: 2020-05-13T15:14:19+08:00
[INFO] Final Memory: 28M/446M
[INFO] ------------------------------------------------------------------------
看上面红色标注的几号,pom.xml依赖了log-manager和httpclient,前者依赖于jcl-over-slf4j,后者依赖于commons-logging,两者冲突了。
解决办法:httpclient排除commons-logging的依赖,见下面红色字体部分
<dependency>
<groupId>io.airlift</groupId>
<artifactId>log-manager</artifactId>
</dependency><dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.1</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
问题2:显示依赖问题排查
代码中使用了slf4j-api,但没有在pom文件写上依赖,idea代码编辑检查也没报错,编译的时候才报错
[INFO] --- maven-dependency-plugin:2.10:analyze-only (default) @ presto-main ---
[WARNING] Used undeclared dependencies found:
[WARNING] org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:34 min
[INFO] Finished at: 2020-05-13T15:59:34+08:00
[INFO] Final Memory: 97M/3127M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.10:analyze-only (default) on project presto-main: Dependency problems found -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
添加上依赖即可
<dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.25</version> </dependency>
问题总结
版本冲突或者依赖冲突对mvn来说是家常便饭,有时不能只关注ERROR,像上面两种情况,问题出在WARNING提示的地方,遇到问题问题解决问题,要找到正确方法。