前言
研讀Mybatis源碼之前,或者一個(gè)項(xiàng)目之前,我選擇了先看一下項(xiàng)目管理配置文件,有個(gè)整體的總攬,同時(shí)也可以學(xué)習(xí)一下此類框架軟件的寫法及一些常用操作,同時(shí)理解一個(gè)完整開源框架需要哪些非編程語言相關(guān)的知識(shí),Mybatis還有 parent-pom文件,非常的長(zhǎng),以后有機(jī)會(huì)希望自己慢慢的能用gradle實(shí)現(xiàn)同樣的功能~
Xml如下,添加了一些標(biāo)簽的解釋.參考史上最全maven pom文件標(biāo)簽詳解,一些依賴和插件也要自己動(dòng)手查查看,慢慢積累~(簡(jiǎn)書引用代碼如何做到自動(dòng)換行?目前沒有找到方法,有知道的可以留言一下,若影響閱讀體驗(yàn)可以把文本復(fù)制出去看..)
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2009-2017 the original author or authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<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><!--聲明項(xiàng)目描述符遵循哪一個(gè)POM模型版本。模型本身的版本很少改變,雖然如此,但它仍然是必不可少的,這是為了當(dāng)Maven引入了新的特性或者其他模型變更的時(shí)候,確保穩(wěn)定性。-->
<parent> <!--父項(xiàng)目的坐標(biāo)。如果項(xiàng)目中沒有規(guī)定某個(gè)元素的值,那么父項(xiàng)目中的對(duì)應(yīng)值即為項(xiàng)目的默認(rèn)值。 坐標(biāo)包括group ID,artifact ID和 version。-->
<!--被繼承的父項(xiàng)目的構(gòu)件標(biāo)識(shí)符-->
<groupId>org.mybatis</groupId><!--被繼承的父項(xiàng)目的全球唯一標(biāo)識(shí)符-->
<artifactId>mybatis-parent</artifactId><!--被繼承的父項(xiàng)目的構(gòu)件標(biāo)識(shí)符-->
<version>28</version><!--被繼承的父項(xiàng)目的版本-->
<relativePath /><!-- 父項(xiàng)目的pom.xml文件的相對(duì)路徑。相對(duì)路徑允許你選擇一個(gè)不同的路徑。默認(rèn)值是../pom.xml。Maven首先在構(gòu)建當(dāng)前項(xiàng)目的地方尋找父項(xiàng) 目的pom,其次在文件系統(tǒng)的這個(gè)位置(relativePath位置),然后在本地倉庫,最后在遠(yuǎn)程倉庫尋找父項(xiàng)目的pom。-->
</parent>
<!--項(xiàng)目的全球唯一標(biāo)識(shí)符,通常使用全限定的包名區(qū)分該項(xiàng)目和其他項(xiàng)目。并且構(gòu)建時(shí)生成的路徑也是由此生成, 如com.mycompany.app生成的相對(duì)路徑為:/com/mycompany/app-->
<!--mybattis的groupId應(yīng)該和父項(xiàng)目的一致,所以這里沒這個(gè)標(biāo)簽</groupId>-->
<artifactId>mybatis</artifactId><!-- 構(gòu)件的標(biāo)識(shí)符,它和group ID一起唯一標(biāo)識(shí)一個(gè)構(gòu)件。換句話說,你不能有兩個(gè)不同的項(xiàng)目擁有同樣的artifact ID和groupID;在某個(gè) 特定的group ID下,artifact ID也必須是唯一的。構(gòu)件是項(xiàng)目產(chǎn)生的或使用的一個(gè)東西,Maven為項(xiàng)目產(chǎn)生的構(gòu)件包括:JARs,源 碼,二進(jìn)制發(fā)布和WARs等。-->
<version>3.4.5-SNAPSHOT</version><!--項(xiàng)目當(dāng)前版本,格式為:主版本.次版本.增量版本-限定版本號(hào)-->
<packaging>jar</packaging><!--項(xiàng)目產(chǎn)生的構(gòu)件類型,例如jar、war、ear、pom。插件可以創(chuàng)建他們自己的構(gòu)件類型,所以前面列的不是全部構(gòu)件類型-->
<name>mybatis</name><!--項(xiàng)目的名稱, Maven產(chǎn)生的文檔用-->
<description><!-- 項(xiàng)目的詳細(xì)描述, Maven 產(chǎn)生的文檔用。 當(dāng)這個(gè)元素能夠用HTML格式描述時(shí)(例如,CDATA中的文本會(huì)被解析器忽略,就可以包含HTML標(biāo) 簽), 不鼓勵(lì)使用純文本描述。如果你需要修改產(chǎn)生的web站點(diǎn)的索引頁面,你應(yīng)該修改你自己的索引頁文件,而不是調(diào)整這里的文檔。-->
The MyBatis SQL mapper framework makes it easier to use a relational database with object-oriented
applications. MyBatis couples objects with stored procedures or SQL statements using a XML descriptor or
annotations. Simplicity is the biggest advantage of the MyBatis data mapper over object relational mapping
tools.
</description>
<url>http://www.mybatis.org/mybatis-3</url> <!--項(xiàng)目主頁的URL, Maven產(chǎn)生的文檔用-->
<inceptionYear>2009</inceptionYear><!--項(xiàng)目創(chuàng)建年份,4位數(shù)字。當(dāng)產(chǎn)生版權(quán)信息時(shí)需要使用這個(gè)值。-->
<contributors><!--項(xiàng)目的其他貢獻(xiàn)者列表-->
<contributor><!--項(xiàng)目的其他貢獻(xiàn)者。參見developers/developer元素-->
<name>Adam Gent</name>
<email>adam.gent@evocatus.com</email>
</contributor>
<contributor>
<name>Andrea Selva</name>
<email>selva.andre@gmail.com</email>
</contributor>
<contributor>
<name>Antonio Sánchez</name>
<email>juntandolineas@gmail.com</email>
</contributor>
<contributor>
<name>Arkadi Shishlov</name>
<email>arkadi.shishlov@gmail.com</email>
</contributor>
<contributor>
<name>Axel Doerfler</name>
<email>axel.doerfler@gmail.com</email>
</contributor>
<contributor>
<name>Chris Dadej</name>
<email>chris.dadej@gmail.com</email>
</contributor>
<contributor>
<name>Denis Vygovskiy</name>
<email>qizant@gmail.com</email>
</contributor>
<contributor>
<name>Franta Mejta</name>
<email>mejta@rewor.cz</email>
</contributor>
<contributor>
<name>Jurriaan Pruys</name>
<email>jurriaan@pruys.com</email>
</contributor>
<contributor>
<name>Keith Wong</name>
<email>wongkwl@gmail.com</email>
</contributor>
<contributor>
<name>Lasse Voss</name>
<email>lasse.voss@motor-talk-gmbh.de</email>
</contributor>
<contributor>
<name>Luke Stevens</name>
<email>nosuchluke@gmail.com</email>
</contributor>
<contributor>
<name>Paul Krause</name>
<email>paulkrause88@alum.mit.edu</email>
</contributor>
<contributor>
<name>Peter Leibiger</name>
<email>kuhnroyal@gmail.com</email>
</contributor>
<contributor>
<name>Riccardo Cossu</name>
<email>riccardo.cossu@gmail.com</email>
</contributor>
<contributor>
<name>Tomá? Neuberg</name>
<email>neuberg@m-atelier.cz</email>
</contributor>
</contributors>
<scm> <!--SCM(Source Control Management)標(biāo)簽允許你配置你的代碼庫,供Maven web站點(diǎn)和其它插件使用。-->
<url>http://github.com/mybatis/mybatis-3</url><!--指向項(xiàng)目的可瀏覽SCM庫(例如ViewVC或者Fisheye)的URL。-->
<connection>scm:git:ssh://github.com/mybatis/mybatis-3.git</connection><!--SCM的URL,該URL描述了版本庫和如何連接到版本庫。欲知詳情,請(qǐng)看SCMs提供的URL格式和列表。該連接只讀。-->
<developerConnection>scm:git:ssh://git@github.com/mybatis/mybatis-3.git</developerConnection><!--給開發(fā)者使用的,類似connection元素。即該連接不僅僅只讀-->
<tag>HEAD</tag><!--當(dāng)前代碼的標(biāo)簽,在開發(fā)階段默認(rèn)為HEAD-->
</scm>
<issueManagement> <!--項(xiàng)目的問題管理系統(tǒng)(Bugzilla, Jira, Scarab,或任何你喜歡的問題管理系統(tǒng))的名稱和URL-->
<system>GitHub Issue Management</system><!--問題管理系統(tǒng)的名字,-->
<url>https://github.com/mybatis/mybatis-3/issues</url><!--該項(xiàng)目使用的問題管理系統(tǒng)的URL-->
</issueManagement>
<ciManagement><!--項(xiàng)目持續(xù)集成信息-->
<system>Travis CI</system><!--持續(xù)集成系統(tǒng)的名字,例如continuum-->
<url>https://travis-ci.org/mybatis/mybatis-3/</url><!--該項(xiàng)目使用的持續(xù)集成系統(tǒng)的URL(如果持續(xù)集成系統(tǒng)有web接口的話)。-->
</ciManagement>
<distributionManagement><!--項(xiàng)目分發(fā)信息,在執(zhí)行mvn deploy后表示要發(fā)布的位置。有了這些信息就可以把網(wǎng)站部署到遠(yuǎn)程服務(wù)器或者把構(gòu)件部署到遠(yuǎn)程倉庫。-->
<site>
<id>gh-pages</id>
<name>Mybatis GitHub Pages</name>
<url>git:ssh://git@github.com/mybatis/mybatis-3.git?gh-pages#</url>
</site>
</distributionManagement>
<properties><!--以值替代名稱,Properties可以在整個(gè)POM中使用,也可以作為觸發(fā)條件(見settings.xml配置文件里activation元素的說明)。格式是<name>value</name>。-->
<maven.compiler.testTarget>1.8</maven.compiler.testTarget>
<maven.compiler.testSource>1.8</maven.compiler.testSource>
<maven.compiler.testCompilerArgument>-parameters</maven.compiler.testCompilerArgument>
<clirr.comparisonVersion>3.3.1</clirr.comparisonVersion>
<findbugs.onlyAnalyze>org.apache.ibatis.*</findbugs.onlyAnalyze>
<osgi.export>org.apache.ibatis.*;version=${project.version};-noimport:=true</osgi.export>
<osgi.import>*;resolution:=optional</osgi.import>
<osgi.dynamicImport>*</osgi.dynamicImport>
</properties>
<dependencies><!-- 繼承自該項(xiàng)目的所有子項(xiàng)目的默認(rèn)依賴信息。這部分的依賴信息不會(huì)被立即解析,而是當(dāng)子項(xiàng)目聲明一個(gè)依賴(必須描述group ID和 artifact ID信息),如果group ID和artifact ID以外的一些信息沒有描述,則通過group ID和artifact ID 匹配到這里的依賴,并使用這里的依賴信息。-->
<!--好多的依賴可以自行百度一下簡(jiǎn)介,我感受有2點(diǎn),1是 mybatis好像并沒有依賴于太多的第三方庫,2是 測(cè)試用的依賴涉及到了一些,單元測(cè)試等等的水還是非常之深的~ -->
<dependency>
<groupId>ognl</groupId>
<artifactId>ognl</artifactId>
<version>3.1.14</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.22.0-CR1</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-typehandlers-jsr310</artifactId>
<version>1.0.2</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<optional>true</optional>
</dependency>
<!-- Don't upgrade to 2.4+ until mybatis switches to java 7 -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.3</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>3.2.5</version>
<optional>true</optional>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.3.4</version> <!-- Version 2.4.0 required jdk8 -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.12.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.7.22</version>
<scope>test</scope>
</dependency>
<!-- Do not go to 2.x until we are on jdk7 -->
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.2_spec</artifactId>
<version>1.0.1.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
<scope>test</scope>
</dependency>
<!-- postgresql driver is required to run the refcursor tests -->
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901-1.jdbc4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>1.7.1</version> <!-- Stay on 1.7.1 to support Java 6 -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>eu.codearte.catch-exception</groupId>
<artifactId>catch-exception</artifactId>
<version>1.4.4</version>
<scope>test</scope>
</dependency>
</dependencies>
<build><!--構(gòu)建項(xiàng)目需要的信息-->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<testCompilerArgument>${maven.compiler.testCompilerArgument}</testCompilerArgument>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludedGroups>${maven.surefire.excludeGroups}</excludedGroups>
<argLine>${argLine} -Xmx2048m</argLine>
<systemProperties>
<property>
<name>derby.stream.error.file</name>
<value>${project.build.directory}/derby.log</value>
</property>
<property>
<name>derby.system.home</name>
<value>${project.build.directory}</value>
</property>
</systemProperties>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pdf-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<artifactSet>
<includes>
<include>org.mybatis:mybatis</include>
<include>ognl:ognl</include>
<include>org.javassist:javassist</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>ognl</pattern>
<shadedPattern>org.apache.ibatis.ognl</shadedPattern>
</relocation>
<relocation>
<pattern>javassist</pattern>
<shadedPattern>org.apache.ibatis.javassist</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<configuration>
<locales>en,es,ja,fr,zh_CN,ko</locales>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>org.apache.ibatis.ognl.*</exclude>
<exclude>org.apache.ibatis.javassist.*</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>${project.basedir}</directory>
<targetPath>META-INF</targetPath>
<includes>
<include>LICENSE</include>
<include>NOTICE</include>
</includes>
</resource>
<resource>
<directory>${project.build.sourceDirectory}</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<testResources>
<testResource>
<directory>${project.build.testSourceDirectory}</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
</testResources>
</build>
<profiles> <!--maven profile可使用操作系統(tǒng)信息,jdk信息,文件是否存在,屬性值等作為依據(jù),來激活相應(yīng)的profile,也可在編譯階段,通過mvn命令加參數(shù) -PprofileId 來手工激活使用對(duì)應(yīng)的profile-->
<!--結(jié)合filter和profile,我們就可以方便的在不同環(huán)境下使用不同的配制-->
<profile>
<id>java16</id>
<activation>
<jdk>1.6</jdk>
</activation>
<properties>
<maven.compiler.testTarget>1.6</maven.compiler.testTarget>
<maven.compiler.testSource>1.6</maven.compiler.testSource>
<maven.compiler.testCompilerArgument />
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<testExcludes>
<testExclude>**/usesjava7/**/*.java</testExclude>
<testExclude>**/usesjava8/**/*.java</testExclude>
</testExcludes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
<profile>
<id>java17</id>
<activation>
<jdk>1.7</jdk>
</activation>
<properties>
<maven.compiler.testTarget>1.7</maven.compiler.testTarget>
<maven.compiler.testSource>1.7</maven.compiler.testSource>
<maven.compiler.testCompilerArgument />
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<testExcludes>
<testExclude>**/usesjava8/**/*.java</testExclude>
</testExcludes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
</project>