正则表达式获取Maven依赖中的groupId

用于打包时剔除第三方jar包



mvn dependency:tree | grep '[\W\w]*:[a-zA-Z0-9_\.-]*:[a-zA-Z0-9]*:[a-zA-Z0-9\.-]*:[a-zA-Z0-9]*' | sed 's/\[INFO\] //g' | sed 's/+- //g' | sed 's/|  //g' | sed 's/\\- //g' | sed 's/ //g'| sed 's/:/,:/g' | cut -d ":" -f1 | sort | uniq



比如,通过mvn dependency:tree只能获取如下内容

[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.xx.xx:xx:jar:0.0.1
[WARNING] 'build.plugins.plugin.version' for org.apache.felix:maven-bundle-plugin is missing. @ line 235, column 21
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO] 
[INFO] -------------------------< com.xx.xx:xx >-------------------------
[INFO] Building chcg_server 0.0.1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:3.1.1:tree (default-cli) @ server ---
[INFO] com.ec.chcg:server:jar:0.0.1
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:2.1.7.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:2.1.7.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:2.1.7.RELEASE:compile
[INFO] |  |  |  +- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO] |  |  |  |  \- ch.qos.logback:logback-core:jar:1.2.3:compile
[INFO] |  |  |  +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.11.2:compile
[INFO] |  |  |  |  \- org.apache.logging.log4j:log4j-api:jar:2.11.2:compile
[INFO] |  |  |  \- org.slf4j:jul-to-slf4j:jar:1.7.26:compile
[INFO] |  |  +- javax.annotation:javax.annotation-api:jar:1.3.2:compile
[INFO] |  |  \- org.yaml:snakeyaml:jar:1.23:runtime
[INFO] |  +- org.springframework.boot:spring-boot-starter-json:jar:2.1.7.RELEASE:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.9.9:compile
[INFO] |  |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0:compile
[INFO] |  |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.9.9:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.9.9:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.9.9:compile
[INFO] |  |  \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.9.9:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.1.7.RELEASE:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:9.0.22:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:9.0.22:compile
[INFO] |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:9.0.22:compile
[INFO] |  +- org.hibernate.validator:hibernate-validator:jar:6.0.17.Final:compile
[INFO] |  |  +- javax.validation:validation-api:jar:2.0.1.Final:compile
[INFO] |  |  +- org.jboss.logging:jboss-logging:jar:3.3.2.Final:compile
[INFO] |  |  \- com.fasterxml:classmate:jar:1.4.0:compile
[INFO] |  +- org.springframework:spring-web:jar:5.1.9.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-beans:jar:5.1.9.RELEASE:compile
[INFO] |  \- org.springframework:spring-webmvc:jar:5.1.9.RELEASE:compile
[INFO] |     +- org.springframework:spring-context:jar:5.1.9.RELEASE:compile
[INFO] |     \- org.springframework:spring-expression:jar:5.1.9.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-thymeleaf:jar:2.1.7.RELEASE:compile
[INFO] |  +- org.thymeleaf:thymeleaf-spring5:jar:3.0.11.RELEASE:compile
[INFO] |  |  \- org.thymeleaf:thymeleaf:jar:3.0.11.RELEASE:compile
[INFO] |  |     +- org.attoparser:attoparser:jar:2.0.5.RELEASE:compile
[INFO] |  |     \- org.unbescape:unbescape:jar:1.1.6.RELEASE:compile
[INFO] |  \- org.thymeleaf.extras:thymeleaf-extras-java8time:jar:3.0.4.RELEASE:compile
[INFO] +- org.mybatis.spring.boot:mybatis-spring-boot-starter:jar:2.1.0:compile
[INFO] |  +- org.mybatis.spring.boot:mybatis-spring-boot-autoconfigure:jar:2.1.0:compile
[INFO] |  +- org.mybatis:mybatis:jar:3.5.2:compile
[INFO] |  \- org.mybatis:mybatis-spring:jar:2.0.2:compile
[INFO] +- org.springframework.boot:spring-boot-starter-jdbc:jar:2.1.7.RELEASE:compile
[INFO] |  +- com.zaxxer:HikariCP:jar:3.2.0:compile
[INFO] |  \- org.springframework:spring-jdbc:jar:5.1.9.RELEASE:compile
[INFO] |     \- org.springframework:spring-tx:jar:5.1.9.RELEASE:compile
[INFO] +- mysql:mysql-connector-java:jar:8.0.17:runtime
[INFO] +- org.springframework.boot:spring-boot-starter-aop:jar:2.1.7.RELEASE:compile
[INFO] |  +- org.springframework:spring-aop:jar:5.1.9.RELEASE:compile
[INFO] |  \- org.aspectj:aspectjweaver:jar:1.9.4:compile
[INFO] +- org.springframework.boot:spring-boot-starter-cache:jar:2.1.7.RELEASE:compile
[INFO] |  \- org.springframework:spring-context-support:jar:5.1.9.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:2.1.7.RELEASE:compile
[INFO] |  +- javax.transaction:javax.transaction-api:jar:1.3:compile
[INFO] |  +- javax.xml.bind:jaxb-api:jar:2.3.1:compile
[INFO] |  |  \- javax.activation:javax.activation-api:jar:1.2.0:compile
[INFO] |  +- org.hibernate:hibernate-core:jar:5.3.10.Final:compile
[INFO] |  |  +- javax.persistence:javax.persistence-api:jar:2.2:compile
[INFO] |  |  +- org.javassist:javassist:jar:3.23.2-GA:compile
[INFO] |  |  +- net.bytebuddy:byte-buddy:jar:1.9.16:compile
[INFO] |  |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  |  +- org.jboss:jandex:jar:2.0.5.Final:compile
[INFO] |  |  +- org.dom4j:dom4j:jar:2.1.1:compile
[INFO] |  |  \- org.hibernate.common:hibernate-commons-annotations:jar:5.0.4.Final:compile
[INFO] |  +- org.springframework.data:spring-data-jpa:jar:2.1.10.RELEASE:compile
[INFO] |  |  +- org.springframework.data:spring-data-commons:jar:2.1.10.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-orm:jar:5.1.9.RELEASE:compile
[INFO] |  \- org.springframework:spring-aspects:jar:5.1.9.RELEASE:compile
[INFO] +- com.sun.jna:jna:jar:3.0.9:compile
[INFO] +- org.springframework.boot:spring-boot-starter-batch:jar:2.1.7.RELEASE:compile
[INFO] |  \- org.springframework.batch:spring-batch-core:jar:4.1.2.RELEASE:compile
[INFO] |     +- javax.batch:javax.batch-api:jar:1.0:compile
[INFO] |     +- org.codehaus.jettison:jettison:jar:1.2:compile
[INFO] |     \- org.springframework.batch:spring-batch-infrastructure:jar:4.1.2.RELEASE:compile
[INFO] |        \- org.springframework.retry:spring-retry:jar:1.2.4.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-devtools:jar:2.1.7.RELEASE:compile (optional) 
[INFO] |  +- org.springframework.boot:spring-boot:jar:2.1.7.RELEASE:compile
[INFO] |  \- org.springframework.boot:spring-boot-autoconfigure:jar:2.1.7.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:2.1.7.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test:jar:2.1.7.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:2.1.7.RELEASE:test
[INFO] |  +- com.jayway.jsonpath:json-path:jar:2.4.0:test
[INFO] |  |  \- net.minidev:json-smart:jar:2.3:test
[INFO] |  |     \- net.minidev:accessors-smart:jar:1.2:test
[INFO] |  |        \- org.ow2.asm:asm:jar:5.0.4:test
[INFO] |  +- junit:junit:jar:4.12:compile
[INFO] |  +- org.assertj:assertj-core:jar:3.11.1:test
[INFO] |  +- org.mockito:mockito-core:jar:2.23.4:test
[INFO] |  |  +- net.bytebuddy:byte-buddy-agent:jar:1.9.16:test
[INFO] |  |  \- org.objenesis:objenesis:jar:2.6:test
[INFO] |  +- org.hamcrest:hamcrest-core:jar:1.3:compile
[INFO] |  +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] |  +- org.skyscreamer:jsonassert:jar:1.5.0:test
[INFO] |  |  \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
[INFO] |  +- org.springframework:spring-core:jar:5.1.9.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-jcl:jar:5.1.9.RELEASE:compile
[INFO] |  +- org.springframework:spring-test:jar:5.1.9.RELEASE:test
[INFO] |  \- org.xmlunit:xmlunit-core:jar:2.6.3:test
[INFO] +- org.springframework.boot:spring-boot-configuration-processor:jar:2.1.7.RELEASE:compile (optional) 
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.5.9:compile
[INFO] |  +- org.apache.httpcomponents:httpcore:jar:4.4.11:compile
[INFO] |  \- commons-codec:commons-codec:jar:1.11:compile
[INFO] +- org.jsoup:jsoup:jar:1.10.2:compile
[INFO] +- net.sf.json-lib:json-lib:jar:jdk15:2.4:compile
[INFO] |  +- commons-beanutils:commons-beanutils:jar:1.8.0:compile
[INFO] |  +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] |  +- commons-lang:commons-lang:jar:2.5:compile
[INFO] |  +- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] |  \- net.sf.ezmorph:ezmorph:jar:1.0.6:compile
[INFO] +- com.google.code.gson:gson:jar:2.8.5:compile
[INFO] +- org:jaudiotagger:jar:2.0.3:compile
[INFO] +- com.thoughtworks.xstream:xstream:jar:1.4.10:compile
[INFO] |  +- xmlpull:xmlpull:jar:1.1.3.1:compile
[INFO] |  \- xpp3:xpp3_min:jar:1.1.4c:compile
[INFO] +- org.springframework.boot:spring-boot-starter-websocket:jar:2.1.7.RELEASE:compile
[INFO] |  +- org.springframework:spring-messaging:jar:5.1.9.RELEASE:compile
[INFO] |  \- org.springframework:spring-websocket:jar:5.1.9.RELEASE:compile
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.7.7:compile
[INFO] |  \- org.slf4j:slf4j-api:jar:1.7.26:compile
[INFO] +- log4j:log4j:jar:1.2.17:compile
[INFO] +- com.google.zxing:core:jar:3.2.1:compile
[INFO] +- com.google.zxing:javase:jar:3.2.1:compile
[INFO] |  \- com.beust:jcommander:jar:1.48:compile
[INFO] +- org.bouncycastle:bcprov-jdk15:jar:1.46:compile
[INFO] +- org.codehaus.xfire:xfire-core:jar:1.2.6:compile
[INFO] |  +- javax.activation:activation:jar:1.1:compile
[INFO] |  +- javax.mail:mail:jar:1.4:compile
[INFO] |  +- wsdl4j:wsdl4j:jar:1.6.3:compile
[INFO] |  +- jaxen:jaxen:jar:1.1.6:compile
[INFO] |  +- stax:stax-api:jar:1.0.1:compile
[INFO] |  +- org.apache.ws.commons:XmlSchema:jar:1.1:compile
[INFO] |  +- org.codehaus.woodstox:wstx-asl:jar:3.2.0:compile
[INFO] |  +- jdom:jdom:jar:1.0:compile
[INFO] |  \- commons-httpclient:commons-httpclient:jar:3.0:compile
[INFO] +- org.springframework.boot:spring-boot-starter-amqp:jar:2.1.7.RELEASE:compile
[INFO] |  \- org.springframework.amqp:spring-rabbit:jar:2.1.8.RELEASE:compile
[INFO] |     +- org.springframework.amqp:spring-amqp:jar:2.1.8.RELEASE:compile
[INFO] |     \- com.rabbitmq:amqp-client:jar:5.4.3:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-redis:jar:2.1.7.RELEASE:compile
[INFO] |  +- org.springframework.data:spring-data-redis:jar:2.1.10.RELEASE:compile
[INFO] |  |  +- org.springframework.data:spring-data-keyvalue:jar:2.1.10.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-oxm:jar:5.1.9.RELEASE:compile
[INFO] |  \- io.lettuce:lettuce-core:jar:5.1.8.RELEASE:compile
[INFO] |     +- io.netty:netty-common:jar:4.1.38.Final:compile
[INFO] |     +- io.netty:netty-handler:jar:4.1.38.Final:compile
[INFO] |     |  +- io.netty:netty-buffer:jar:4.1.38.Final:compile
[INFO] |     |  \- io.netty:netty-codec:jar:4.1.38.Final:compile
[INFO] |     +- io.netty:netty-transport:jar:4.1.38.Final:compile
[INFO] |     |  \- io.netty:netty-resolver:jar:4.1.38.Final:compile
[INFO] |     \- io.projectreactor:reactor-core:jar:3.2.11.RELEASE:compile
[INFO] |        \- org.reactivestreams:reactive-streams:jar:1.0.2:compile
[INFO] +- com.baidu.aip:java-sdk:jar:4.8.0:compile
[INFO] |  \- org.json:json:jar:20160810:compile
[INFO] +- org.apache.poi:poi:jar:3.17:compile
[INFO] |  \- org.apache.commons:commons-collections4:jar:4.1:compile
[INFO] +- org.apache.poi:poi-scratchpad:jar:3.17:compile
[INFO] +- org.apache.poi:poi-ooxml:jar:3.17:compile
[INFO] |  \- com.github.virtuald:curvesapi:jar:1.04:compile
[INFO] \- org.apache.poi:poi-ooxml-schemas:jar:3.17:compile
[INFO]    \- org.apache.xmlbeans:xmlbeans:jar:2.6.0:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.075 s
[INFO] Finished at: 2019-11-22T09:24:48+08:00
[INFO] ------------------------------------------------------------------------

最终通过正则表达式获取效果如下:


antlr,
ch.qos.logback,
com.baidu.aip,
com.beust,
com.fasterxml,
com.fasterxml.jackson.core,
com.fasterxml.jackson.datatype,
com.fasterxml.jackson.module,
com.github.virtuald,
com.google.code.gson,
com.google.zxing,
com.jayway.jsonpath,
com.rabbitmq,
com.sun.jna,
com.thoughtworks.xstream,
com.vaadin.external.google,
com.zaxxer,
commons-beanutils,
commons-codec,
commons-collections,
commons-httpclient,
commons-lang,
commons-logging,
io.lettuce,
io.netty,
io.projectreactor,
javax.activation,
javax.annotation,
javax.batch,
javax.mail,
javax.persistence,
javax.transaction,
javax.validation,
javax.xml.bind,
jaxen,
jdom,
junit,
log4j,
mysql,
net.bytebuddy,
net.minidev,
net.sf.ezmorph,
net.sf.json-lib,
org,
org.apache.commons,
org.apache.httpcomponents,
org.apache.logging.log4j,
org.apache.poi,
org.apache.tomcat.embed,
org.apache.ws.commons,
org.apache.xmlbeans,
org.aspectj,
org.assertj,
org.attoparser,
org.bouncycastle,
org.codehaus.jettison,
org.codehaus.woodstox,
org.codehaus.xfire,
org.dom4j,
org.hamcrest,
org.hibernate,
org.hibernate.common,
org.hibernate.validator,
org.javassist,
org.jboss,
org.jboss.logging,
org.json,
org.jsoup,
org.mockito,
org.mybatis,
org.mybatis.spring.boot,
org.objenesis,
org.ow2.asm,
org.reactivestreams,
org.skyscreamer,
org.slf4j,
org.springframework,
org.springframework.amqp,
org.springframework.batch,
org.springframework.boot,
org.springframework.data,
org.springframework.retry,
org.thymeleaf,
org.thymeleaf.extras,
org.unbescape,
org.xmlunit,
org.yaml,
stax,
wsdl4j,
xmlpull,
xpp3,


你可能感兴趣的:(SpringBoot,maven,shell)