PostgreSQL JDBC 源码编译jar包、执行JDBC测试集(Gradle方式编译)

1. 查看 java 环境

[zhang@localhost ~]$ java -version
openjdk version "1.8.0_362"
OpenJDK Runtime Environment (build 1.8.0_362-b08)
OpenJDK 64-Bit Server VM (build 25.362-b08, mixed mode)

2. Gradle 方式编译

直接进入 pgjdbc 源码根目录,执行下面的命令,它会自动下载依赖的包。

./gradlew tasks # lists available tasks

./gradlew build # builds everything
./gradlew assemble # build the artifacts
./gradlew build -x test # build the artifacts, verify code style, skip tests
./gradlew javadoc # build javadoc

./gradlew check # verify code style, execute tests
./gradlew style # update code formatting (for auto-correctable cases) and verify style
./gradlew styleCheck # report code style violations

./gradlew test # execute tests
./gradlew test --tests org.postgresql.test.ssl.SslTest # execute test by class
./gradlew test -PincludeTestTags=!org.postgresql.test.SlowTests # skip slow tests
./gradlew test -PjdkTestVersion=21 --tests org.postgresql.test.ssl.SslTest # execute test with Java 21

./gradlew parameters # list most build parameters like jdkTestVersion above

如果有依赖包下载不了,可以手动下载,将手动下载的文件放入 GRADLE_USER_HOME 环境变量指定的目录中。然后再试。具体子目录是根据文件 gradle-wrapper.properties 中的配置而定。

如下:

export GRADLE_USER_HOME=/home/zhang/git/pgjdbc/gradle/wrapper

# gradle-wrapper.properties 文件路径:
/home/zhang/git/pgjdbc/gradle/wrapper/gradle-wrapper.properties

gradle-wrapper.properties 文件中的内容,如下: vim gradle-wrapper.properties

# Copyright (c) 2019, PostgreSQL Global Development Group
# See the LICENSE file in the project root for more information.

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=3239b5ed86c3838a37d983ac100573f64c1f3fd8e1eb6c89fa5f9529b5ec091d
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

比如在我的环境中是下面的目录:

/home/zhang/git/pgjdbc/gradle/wrapper/wrapper/dists/gradle-6.7.1-bin/bwlcbys1h7rz3272sye1xwiv6

将 gradle-6.7.1-bin.zip 文件放入上述目录后,再重新执行。

编译成功后,jar 文件位于目录:

pgjdbc/pgjdbc-jre6/build/libs
pgjdbc/pgjdbc-jre7/build/libs

3. 执行 jdbc 测试集

先创建一个 5432 端口的数据库,创建数据库 test,用户 test、postgres,对用户进行授权。

create database test;
create user postgres with superuser login;
create user test with superuser login;
grant all on database test to test;

执行:

./gradlew build
或者
./gradlew test

如果上述命令执行过程中有代码风格检查相关的报错,可以先执行下面几个命令后,再重试。

./gradlew style
./gradlew styleCheck

文章评论

0条评论