记录一次WhatTheFuck经历

whatthefuck · 浏览次数 : 0

小编点评

## WhatTheFuck...,你又是我吗?! 终于找到了问题的根源了! Thanks to your detailed description, we can pinpoint the culprit: the `skip=true` configuration within the `build` section of your `pom.xml` file. This directive is responsible for skipping the packaging phase and not generating the `jar` file. **The problem:** The `skip=true` setting is effectively overriding the globally defined `maven.compiler.source` and `maven.compiler.target` settings. This means the compiler is instructed to use an outdated JDK version (1.5 in your case) for the build process. **The solution:** The solution is to explicitly set the correct JDK version in the `maven.compiler.source` and `maven.compiler.target` properties within the `build` section of your `pom.xml` file. This will ensure that the compiler uses the specified JDK version and generates the `jar` file correctly. **Additional notes:** * It's important to understand that setting the `maven.compiler.source` and `maven.compiler.target` properties globally might not be ideal, as it could override the globally defined settings. * The `skip` configuration is only applied at the project level, not at the global level. This means that the global `maven.compiler.source` and `maven.compiler.target` settings still apply. * For future projects, it's recommended to define the compiler version directly within the `build` section of the `pom.xml` file to avoid any version conflicts. **The moral of the story:** Always pay close attention to error messages and understand the underlying cause before jumping into conclusions. Don't hesitate to seek help or consult the documentation if needed.

正文

起因

很早之前就一直在维护一个git仓库,平时调研什么组件就会在里面新建一个springboot的工程用来编写示例代码。

最一开始使用的是SpringInitializr,后来网站更新之后,只能生成JDK17+的工程,WhatTheFuck?近期刚从8切换到11.

于是弃用并改用 StartAliyun

今天调研ClickHouse,生成的工程pom-build是这个样子的 :



 <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${spring-boot.version}</version>
                <configuration>
                    <mainClass>com.ramble.clickhouse.ClickhouseApplication</mainClass>
                    <skip>true</skip>
                </configuration>
                <executions>
                    <execution>
                        <id>repackage</id>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>



然后发现打的jar只有7KB,WhatTheFuck!我需要它能生成可以正常运行的jar。

后面就是围绕怎么让maven输出jar展开了。

使用Spring-boot-maven-plugin打包

思虑片刻,想起来了,之前遇到过这样的问题,原因是用maven-compiler-plugin打包就不行,需要用Spring-boot-maven-plugin,于是删除了 maven-compiler-plugin 所在的plugin节点。

新问题出现了:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project clickhouse: Compilation failure: Compilation failure: 
[ERROR] 不再支持源选项 5。请使用 6 或更高版本。
[ERROR] 不再支持目标选项 1.5。请使用 1.6 或更高版本。

WhatTheFuck!!!怎么还1.5了,那里冒出来的,明明在StartAliyun选中的是11。

解决1.5问题

可以肯定的是打包的时候找到的JDK版本是1.5,而预期的是11,预期和实际不一致,所以是设置的问题。

按照经验来说这时候该检查 IDEA SETTINGSProjectStructure了,检查的结果是这两个位置确实是1.5。

好消息是报错的直接原因找到了,坏消息是根本原因还没有找到。

在看一下报错log,发现了这一句话:

Failed to execute goal......

也就是说它找的是全局级别的设置,而不是我项目中设置的,那这个全局是在哪里呢?难道是maven的settings.xml?

同时将去掉的maven-compiler-plugin恢复回来package又正常了。这里基本可以确认 goal 就是指 Maven 的settings.xml了, 因为maven-compiler-plugin中设置了JDK。

那问题太似乎简单了,在settings.xml中设置一下不就行了,代码如下:


<profile>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>  
        <maven.compiler.target>11</maven.compiler.target>  
    </properties>
</profile>


满心欢喜的试一波,哎哟,package不报错了。

然而,生成的jar还是7KB。。。。。。 WhatTheFuck.....

先稳一波,虽然通过设置全局解决了,但是也仅解决了当下的问题,万一明天再搞个JDK22的项目,不还是会预期和实际不一致???

既然全局的settings.xml中设置jdk生效,那工程中设置一样生效,因为依稀记得好好好几年前撸MAVEN的时候工程中的配置会覆盖全局的,于是在pom中的properties下添加上述配置,果然好使。

skip

后面的故事就是:

  • 反复观看package-log
  • 反复检验生成的代码
  • baidu&google
  • chatGPT
  • ......

最终,当我把这个工程的pom和其他正常的工程pom做对比的时候,发现多了一个skip=true的配置


<build>
    <plugins>
        <plugin>
            ......
            <configuration>
                ......
                <skip>true</skip>
            </configuration>
           ......
        </plugin>
    </plugins>
</build>


skip什么意思?跳过。

你要跳过什么?反正你是跳过了!跳过了就7KB了!!!

精准搜索了一下,这里的跳过是:跳过打包

WhatTheFuck......

注释这个之后,问题确实解决了,好了,天晴了,雨停了......

可是,为什么StartAliyun默认要Skip=true呢?着实想不明白,不行我还得找找其他的 Initializr ,这个不喜欢用。

总结

  • 遇事不要慌,心态最重要
  • 不要怕麻烦,在不影响团队和交付物的情况下,应该死磕
  • 平时知识的积累还是需要系统化一些,不可留在皮毛,亦或是参差不齐,应该是由浅入深,结构化,系统化。这样在遇到问题的时候排查思路和方向更靠谱

与记录一次WhatTheFuck经历相似的内容:

记录一次WhatTheFuck经历

起因 很早之前就一直在维护一个git仓库,平时调研什么组件就会在里面新建一个springboot的工程用来编写示例代码。 最一开始使用的是SpringInitializr,后来网站更新之后,只能生成JDK17+的工程,WhatTheFuck?近期刚从8切换到11. 于是弃用并改用 StartAliy

记一次ThreadLocal中的用户信息混乱问题

记录一次开发中遇到的关于 ThreadLocal 问题,场景是数据库表中的操作人总是无缘无故的被更改,排查了几遍代码才发现是 ThreadLocal 没有及时清理导致的。

记录一次安装PIDtoolBox报缺少jvm.dll问题。

背景: 1.在安装PIDtoolBox时,报 安装程序错误 安装程序无法启动JVM。 could not find file C:\Users\AdministratorAppData\Local\MathWorks\app installer cache\R2018b\ win64vinstall

记录一次fs通话无声的问题

概述 freeswitch是一款简单好用的VOIP开源软交换平台。 fs的实际应用中,由于网络、配置等问题,经常会产生通话无声的问题。 环境 CentOS 7.9 freeswitch 1.10.7 问题描述 部署一台新服务器,作为SBC,对接B路,部署简图如下。 A -- fs1 -- fs2(f

[转帖]记录一次spring-boot程序内存泄露排查

现象 spring boot项目jvm启动配置-Xms4g -Xmx4g,然而很不幸的是程序所占的内存越来越高,都达到了12个多G,只能临时重启服务 常用命令 jstat -class PIDjstat -compiler PIDjstat -gc PIDjstat -gccapacity PIDj

[转帖]记录一次前端内存泄漏排查经历

https://juejin.cn/post/6844904019983335438 对于前端的“内存泄漏”这个东西,说实话我只在书上看到过: 闭包、匿名函数和事件绑定尤其容易造成内存泄漏。 然而这些操作造成的“内存泄漏”究竟是什么样子的?如何排查?虽然很好奇,却不得而知。直到这次公司应用频繁出现浏

记录一次前端表格选型过程

> 摘要:本文由葡萄城技术团队于博客园原创并首发。转载请注明出处:[葡萄城官网](https://www.grapecity.com.cn/),葡萄城为开发者提供专业的开发工具、解决方案和服务,赋能开发者。 ## 客户需求: 最近,接到一个客户项目,前期沟通时,客户说,我们日常基本都是使用Excel

记录一次gcc的编译

在deepin23上编译gcc13.2 deepin20素以软件版本过老被人诟病,换成最新的deepin23之后情况大有好转,但是gcc版本为11.2,鄙人对此仍有意见,所以特意研究了如何编译一份较新的gcc来用。 1.下载源码包 http://mirrors.ustc.edu.cn/gnu/gcc

记录一次全栈经验,所有遇到的坑。(文中无需梯子,免费使用chatGPT方法喔)

## 1、先推荐一下自己搭的网站 ### 1.1 网站地址:[chatGPT](https://www.hangyejingling.cn/) ### 1.2 建站原因 为了方便大家在国内使用chatGPT,所以我调研了一下。在国内用腾讯云使用代理访问,gpt3.5API。最后模仿了openAI的官

(性能测试)--记录一次高可用场景导致CPU资源升高

测试场景:高可用场景--限流测试; 被测交易:查询类交易,HTTP协议; 交易链路:jmeter - web - coimpre(前置服务) -- coimbp -- cobp (coimbp 、coimpre 都会访问同一个数据库); 注:cobp 为合肥机房,其他服务均为北京机房,要注意跨网段存