文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

screw Maven插件方式运行时在编译打包时跳过执行的问题如何解决

2023-07-05 15:11

关注

今天小编给大家分享一下screw Maven插件方式运行时在编译打包时跳过执行的问题如何解决的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。

解决screw Maven插件方式运行时,在编译打包时跳过执行的问题

问题描述

在引入screw 进行数据库文档生成,并且使用Maven插件方式运行时,在执行项目打包时,会自动运行该插件。导致在不需要重新生成数据库文档时,也会去生成数据库文档。并且通常数据库文档生成是基于开发环境的数据库的,对于非开发环境的自动打包处理环境,往往是无法访问开发环境数据库,这也会导致项目的打包出错的问题。出错信息如下:

不带-X参数的出错信息:

[INFO] --- screw-maven-plugin:1.0.5:run (default) @ java-abc-cids-interfaces ---
[INFO] Database design document generation begins ????
[INFO] screw - Starting...
Build step 'Invoke top-level Maven targets' marked build as failure

-X参数的出错信息:

[INFO] Database design document generation begins ????
[DEBUG] Driver class com.mysql.cj.jdbc.Driver found in Thread context class loader ClassRealm[plugin>cn.smallbun.screw:screw-maven-plugin:1.0.5, parent: jdk.internal.loader.ClassLoaders$AppClassLoader@ba8a1dc]
[DEBUG] screw - configuration:
[DEBUG] allowPoolSuspension.............false
[DEBUG] autoCommit......................true
[DEBUG] catalog.........................none
[DEBUG] connectionInitSql...............none
[DEBUG] connectionTestQuery.............none
[DEBUG] connectionTimeout...............30000
[DEBUG] dataSource......................none
[DEBUG] dataSourceClassName.............none
[DEBUG] dataSourceJNDI..................none
[DEBUG] dataSourceProperties............{useInformationSchema=true, password=<masked>}
[DEBUG] driverClassName................."com.mysql.cj.jdbc.Driver"
[DEBUG] exceptionOverrideClassName......none
[DEBUG] healthCheckProperties...........{}
[DEBUG] healthCheckRegistry.............none
[DEBUG] idleTimeout.....................600000
[DEBUG] initializationFailTimeout.......1
[DEBUG] isolateInternalQueries..........false
[DEBUG] jdbcUrl.........................jdbc:mysql://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[DEBUG] leakDetectionThreshold..........0
[DEBUG] maxLifetime.....................1800000
[DEBUG] maximumPoolSize.................10
[DEBUG] metricRegistry..................none
[DEBUG] metricsTrackerFactory...........none
[DEBUG] minimumIdle.....................10
[DEBUG] password........................<masked>
[DEBUG] poolName........................"screw"
[DEBUG] readOnly........................false
[DEBUG] registerMbeans..................false
[DEBUG] scheduledExecutor...............none
[DEBUG] schema..........................none
[DEBUG] threadFactory...................internal
[DEBUG] transactionIsolation............default
[DEBUG] username........................"xxxxx"
[DEBUG] validationTimeout...............5000
[INFO] screw - Starting...
[DEBUG] screw - Failed to create/setup connection: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
[DEBUG] screw - Cannot acquire connection from data source
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException (SQLError.java:174)
    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException (SQLExceptionsMapping.java:64)
    at com.mysql.cj.jdbc.ConnectionImpl.createNewIO (ConnectionImpl.java:836)
    at com.mysql.cj.jdbc.ConnectionImpl.<init> (ConnectionImpl.java:456)
    at com.mysql.cj.jdbc.ConnectionImpl.getInstance (ConnectionImpl.java:246)
    at com.mysql.cj.jdbc.NonRegisteringDriver.connect (NonRegisteringDriver.java:197)
    at com.zaxxer.hikari.util.DriverDataSource.getConnection (DriverDataSource.java:138)
    at com.zaxxer.hikari.pool.PoolBase.newConnection (PoolBase.java:358)
    at com.zaxxer.hikari.pool.PoolBase.newPoolEntry (PoolBase.java:206)
    at com.zaxxer.hikari.pool.HikariPool.createPoolEntry (HikariPool.java:477)
    at com.zaxxer.hikari.pool.HikariPool.checkFailFast (HikariPool.java:560)
    at com.zaxxer.hikari.pool.HikariPool.<init> (HikariPool.java:115)
    at com.zaxxer.hikari.HikariDataSource.<init> (HikariDataSource.java:81)
    at cn.smallbun.screw.maven.plugin.mojo.RunDocMojo.getDataSource (RunDocMojo.java:274)
    at cn.smallbun.screw.maven.plugin.mojo.RunDocMojo.execute (RunDocMojo.java:197)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    ...

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:10 min
[INFO] Finished at: 2023-03-20T13:23:57+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal cn.smallbun.screw:screw-maven-plugin:1.0.5:run (default) on project java-abc-cids-interfaces: Execution default of goal cn.smallbun.screw:screw-maven-plugin:1.0.5:run failed: Failed to initialize pool: Communications link failure
[ERROR] 
[ERROR] The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.: connect timed out
[ERROR] -> [Help 1] 

调研

通常的对于Maven插件跳过使用,我们只需要找插件的对应的skip 参数,然后在打包时通过-D 参数来修改这个参数即可,但通过阅读这个插件的源码,并且开启Maven的-X 参数执行,都没有在这个插件中找到skip 参数。

插件启动执行代码位置:https://gitcode.net/mirrors/pingfangushi/screw/-/blob/master/screw-maven-plugin/src/main/java/cn/smallbun/screw/maven/plugin/mojo/RunDocMojo.java

通过查看代码得知,插件的默认触发执行的PhaseCOMPILE,因此解决的思路就有了。

解决方案

方案1

注释掉插件引入代码,在开发环境需要手动执行的时候,再放开注释。

方案2

不再写死配置的Phase ,而是指定一个变量,由运行Maven命令时,通过参数-D 传入正确的Phase ,而不需要执行的时候,传入一个不存在的Phase 或者干脆不传入Phase 即可。

修改前:

      <plugin>        <groupId>cn.smallbun.screw</groupId>        <artifactId>screw-maven-plugin</artifactId>        <version>1.0.5</version>        <dependencies>          <!-- HikariCP -->          <dependency>            <groupId>com.zaxxer</groupId>            <artifactId>HikariCP</artifactId>            <version>3.4.5</version>          </dependency>          <!--mysql driver-->          <dependency>            <groupId>mysql</groupId>            <artifactId>mysql-connector-java</artifactId>            <version>8.0.20</version>          </dependency>        </dependencies>        <configuration>          ... 省略        </configuration>        <executions>          <execution>            <phase>compile</phase>            <goals>              <goal>run</goal>            </goals>          </execution>        </executions>      </plugin>

修改后:

...      <plugin>        <groupId>cn.smallbun.screw</groupId>        <artifactId>screw-maven-plugin</artifactId>        <version>1.0.5</version>        <dependencies>          <!-- HikariCP -->          <dependency>            <groupId>com.zaxxer</groupId>            <artifactId>HikariCP</artifactId>            <version>3.4.5</version>          </dependency>          <!--mysql driver-->          <dependency>            <groupId>mysql</groupId>            <artifactId>mysql-connector-java</artifactId>            <version>8.0.20</version>          </dependency>        </dependencies>        <configuration>          ... 省略        </configuration>        <executions>          <execution>            <phase>${mvn.screw.skip}</phase>            <goals>              <goal>run</goal>            </goals>          </execution>        </executions>      </plugin>

Maven 运行的方法:

clean package -Dmvn.screw.skip=none -f pom.xml 或者 clean package -f pom.xml

clean package -Dmvn.screw.skip=compile -f pom.xml

screw:run -f pom.xml

以上就是“screw Maven插件方式运行时在编译打包时跳过执行的问题如何解决”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注编程网行业资讯频道。

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     801人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     348人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     311人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     432人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     220人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-后端开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯