screw?Maven插件方式運(yùn)行時(shí)在編譯打包時(shí)跳過執(zhí)行的問題解決方法
解決screw Maven插件方式運(yùn)行時(shí),在編譯打包時(shí)跳過執(zhí)行的問題
問題描述
在引入screw 進(jìn)行數(shù)據(jù)庫(kù)文檔生成,并且使用Maven插件方式運(yùn)行時(shí),在執(zhí)行項(xiàng)目打包時(shí),會(huì)自動(dòng)運(yùn)行該插件。導(dǎo)致在不需要重新生成數(shù)據(jù)庫(kù)文檔時(shí),也會(huì)去生成數(shù)據(jù)庫(kù)文檔。并且通常數(shù)據(jù)庫(kù)文檔生成是基于開發(fā)環(huán)境的數(shù)據(jù)庫(kù)的,對(duì)于非開發(fā)環(huán)境的自動(dòng)打包處理環(huán)境,往往是無法訪問開發(fā)環(huán)境數(shù)據(jù)庫(kù),這也會(huì)導(dǎo)致項(xiàng)目的打包出錯(cuò)的問題。出錯(cuò)信息如下:
不帶-X
參數(shù)的出錯(cuò)信息:
[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
參數(shù)的出錯(cuò)信息:
[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 failureThe 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 failureThe 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]
調(diào)研
通常的對(duì)于Maven插件跳過使用,我們只需要找插件的對(duì)應(yīng)的skip
參數(shù),然后在打包時(shí)通過-D
參數(shù)來修改這個(gè)參數(shù)即可,但通過閱讀這個(gè)插件的源碼,并且開啟Maven的-X
參數(shù)執(zhí)行,都沒有在這個(gè)插件中找到skip
參數(shù)。
插件啟動(dòng)執(zhí)行代碼位置:https://gitcode.net/mirrors/pingfangushi/screw/-/blob/master/screw-maven-plugin/src/main/java/cn/smallbun/screw/maven/plugin/mojo/RunDocMojo.java
通過查看代碼得知,插件的默認(rèn)觸發(fā)執(zhí)行的Phase
是COMPILE
,因此解決的思路就有了。
解決方案
方案1
注釋掉插件引入代碼,在開發(fā)環(huán)境需要手動(dòng)執(zhí)行的時(shí)候,再放開注釋。
方案2
不再寫死配置的Phase ,而是指定一個(gè)變量,由運(yùn)行Maven命令時(shí),通過參數(shù)-D
傳入正確的Phase
,而不需要執(zhí)行的時(shí)候,傳入一個(gè)不存在的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 運(yùn)行的方法:
- 不需要運(yùn)行
clean package -Dmvn.screw.skip=none -f pom.xml
或者 clean package -f pom.xml
- 需要運(yùn)行
clean package -Dmvn.screw.skip=compile -f pom.xml
- 單獨(dú)運(yùn)行:
screw:run -f pom.xml
到此這篇關(guān)于screw Maven插件方式運(yùn)行時(shí)在編譯打包時(shí)跳過執(zhí)行的問題解決方法的文章就介紹到這了,更多相關(guān)screw Maven編譯打包跳過執(zhí)行內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
使用Java第三方實(shí)現(xiàn)發(fā)送短信功能
這篇文章主要介紹了使用Java第三方實(shí)現(xiàn)發(fā)送短信功能,在一些開發(fā)中,經(jīng)常需要有給用戶發(fā)送短信接收驗(yàn)證碼的功能,那么在Java中該如何實(shí)現(xiàn)呢,今天我們就一起來看一看2023-03-03mybatis抽取基類BaseMapper增刪改查的實(shí)現(xiàn)
目前項(xiàng)目當(dāng)中使用mapper.xml文件方式對(duì)數(shù)據(jù)庫(kù)進(jìn)行操作,但是每個(gè)里邊都有增/刪/改/查,為了方便開發(fā),把這些公共的代碼提取出來,不用當(dāng)做基類,不用每個(gè)Mapper文件都寫了,本文就詳細(xì)的介紹一下實(shí)現(xiàn)方法2021-09-09Maven一鍵部署Springboot到Docker倉(cāng)庫(kù)為自動(dòng)化做準(zhǔn)備(推薦)
這篇文章主要介紹了Maven一鍵部署Springboot到Docker倉(cāng)庫(kù),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-07-07詳解IDEA2020新建spring項(xiàng)目和c3p0連接池的創(chuàng)建和使用
C3P0是一個(gè)開源的JDBC連接池,它實(shí)現(xiàn)了數(shù)據(jù)源和JNDI綁定,本文就使用Spring實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08Servlet輸出一個(gè)驗(yàn)證碼圖片的實(shí)現(xiàn)方法實(shí)例
這篇文章主要給大家介紹了關(guān)于Servlet輸出一個(gè)驗(yàn)證碼圖片的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-01-01Java接收xml格式參數(shù)轉(zhuǎn)為json的方法
文章主要介紹了如何使用JAXB將XML格式的參數(shù)接收并轉(zhuǎn)換為Java實(shí)體類,然后將實(shí)體類轉(zhuǎn)換為JSON格式,文中提到在實(shí)體類中使用`@XmlElement`和`@JsonProperty`注解的重要性,以及如何處理復(fù)雜的XML結(jié)構(gòu)2024-11-11DolphinScheduler容錯(cuò)Master源碼分析
這篇文章主要為大家介紹了DolphinScheduler容錯(cuò)Master源碼分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02