Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

内嵌 jsqlparser 以规避版本冲突 #784

Merged
merged 1 commit into from
Nov 19, 2023

Conversation

moonfruit
Copy link
Contributor

@moonfruit moonfruit commented Nov 17, 2023

项目中有时会引用jsqlparser,但是由于jsqlparser各版本之间总是会有兼容性问题,经常会面临版本冲突的问题。
所以,我建议pagehelper将自己所使用的jsqlparser内嵌进 jar 包以规避此类问题。

maven-shade-plugin可以在打包时将所有对net.sf.jsqlparser的引用重定向到com.github.pagehelper.jsqlparser,这样这部份代码将只被pagehelper使用,而不影响外部项目。不管pagehelper使用什么版本的jsqlparser,外部项目使用什么版本的jsqlparser都不会互相干扰。同时maven-shade-plugin可以生成一个新的不包含对jsqlparser依赖的pom.xml,用于项目发布。

@pagehelper
Copy link
Owner

👍 做的很好!!!

在这个基础上我想发布两种jar包,包含jsqlparser和默认不包含的。

将shade配置改为profile,增加一个可选的 <classifier>standalone</classifier> 来标记内嵌jsqlparser的版本。

关联 #778, #782

@moonfruit
Copy link
Contributor Author

使用classifier可能会有问题。原因在于standalone的 jar 和原版 jar 使用的是同一个pom.xml,这将使standalone的 jar 也会去依赖已经内嵌的jsqlparser。不知道有没有办法解决。

独立发布一个artifact可能会好一点儿。直接创建一个空项目同时内嵌 pagehelperjsqlparser,其中pagehelper不重定向包名,而jsqlparser重定向包名。

@moonfruit
Copy link
Contributor Author

使用如下的配置项可以在生成原版jar的同时生成<classifier>standalone</classifier>的内嵌jar。但是就像我上面说的这样的jar使用的是原版的pom.xml依然保留有对jsqlparser的依赖,实际使用时可能需要手动添加<exclusion>

<createDependencyReducedPom>false</createDependencyReducedPom>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>standalone</shadedClassifierName>

@moonfruit
Copy link
Contributor Author

moonfruit commented Nov 17, 2023

@pagehelper 我写了一个同时内嵌pagehelperjsqlparserpom.xml,你可以参考。这样可以生成独立的artifact可以有独立的pom.xml和独立的依赖。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper-standalone</artifactId>
    <version>6.0.0</version>

    <dependencies>
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.5.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <keepDependenciesWithProvidedScope>false</keepDependenciesWithProvidedScope>
                            <artifactSet>
                                <includes>
                                    <include>com.github.pagehelper:*</include>
                                    <include>com.github.jsqlparser:*</include>
                                </includes>
                            </artifactSet>
                            <filters>
                                <filter>
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>META-INF/MANIFEST.MF</exclude>
                                    </excludes>
                                </filter>
                                <filter>
                                    <artifact>com.github.jsqlparser:*</artifact>
                                    <excludes>
                                        <exclude>META-INF/maven/**</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                            <relocations>
                                <relocation>
                                    <pattern>net.sf.jsqlparser</pattern>
                                    <shadedPattern>com.github.pagehelper.jsqlparser</shadedPattern>
                                </relocation>
                            </relocations>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

@pagehelper
Copy link
Owner

用profile就行,第一次deploy走默认,第二次deploy指定shade方式,不需要一次构建两个。

@pagehelper pagehelper merged commit ff87ede into pagehelper:master Nov 19, 2023
@pagehelper
Copy link
Owner

这种方式使用同一个pom.xml确实有问题,简单考虑只能通过版本号额外的后缀来区分了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants