mavenを使ってpostgresql-42.2.12.jarとpostgresql-42.2.12-sources.jarをビルドした時のメモ
用意するもの
-
pgjdbcソース一式
https://github.com/pgjdbc/pgjdbc
アーカイブをダウンロードしpgjdbc-masterに展開 -
mavenとhttpdを用意
https://maven.apache.org/install.html
maven本体とapacheが普通に使えるように設定
apacheはローカルリポジトリでも使用するためのhttpd。C:/Apache24にインストール -
JDK 1.8
環境変数のJAVA_HOMEの設定は必須
ビルド
- cd pgjdbc
- pom.xmlファイルを作成を以下のように作成しコマンドプロンプトでmvn deployを実行しtargetにjarが生成。
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2019, PostgreSQL Global Development Group
~ See the LICENSE file in the project root for more information.
-->
<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>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<packaging>jar</packaging>
<name>PostgreSQL JDBC Driver - JDBC 4.2</name>
<version>42.2.12</version>
<description>Java JDBC 4.2 (JRE 8+) driver for PostgreSQL database</description>
<url>https://github.com/pgjdbc/pgjdbc</url>
<licenses>
<license>
<name>BSD-2-Clause</name>
<url>https://jdbc.postgresql.org/about/license.html</url>
</license>
</licenses>
<organization>
<name>PostgreSQL Global Development Group</name>
<url>https://jdbc.postgresql.org/</url>
</organization>
<properties>
<!-- Require JDK 1.8 or later -->
<javac.target>1.8</javac.target>
<encoding>UTF-8</encoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<project.resources.sourceEncoding>UTF-8</project.resources.sourceEncoding>
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<maven-jar-plugin.version>2.6</maven-jar-plugin.version>
<!--
<maven-javadoc-plugin.version>3.0.1</maven-javadoc-plugin.version>
-->
<maven.test.skip>true</maven.test.skip>
<skipTest>true</skipTest>
</properties>
<repositories>
<repository>
<id>private.repository</id>
<name>PrivateRepository</name>
<url>http://127.0.0.1/maven/repo/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>private.repository-snapshot</id>
<name>PrivateRepository-snapshot</name>
<url>http://127.0.0.1/maven/repo-snapshot/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>deploy-repository</id>
<name>deployRepository</name>
<url>file:///C:/Apache24/htdocs/home/maven/repo</url>
</repository>
<snapshotRepository>
<id>deploy-repository</id>
<name>deployRepository</name>
<url>file:///C:/Apache24/htdocs/home/maven/repo-snapshot</url>
</snapshotRepository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna-platform</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>com.github.dblock.waffle</groupId>
<artifactId>waffle-jna</artifactId>
<version>1.8.1</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.framework</artifactId>
<version>1.9.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.jdbc</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.ongres.scram</groupId>
<artifactId>client</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>se.jiderhamn</groupId>
<artifactId>classloader-leak-test-framework</artifactId>
<version>1.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/version</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<argLine>-Xmx1536m</argLine>
<systemPropertyVariables>
<build.properties.relative.path>.</build.properties.relative.path>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
<!--
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
-->
</plugins>
</build>
</project>
maven
mavenは非常に便利でビルドに必要なjarをかき集めてくれます。
jarのバージョンの違いで動かないという問題をなくせます。
pom.xmlの敷居が高いので導入するのに理解が必要です。
pom.xmlを完成してしまえばターゲットになるjarをコマンド一つで作り出せます。