美文网首页
Mybatis 源码之pom.xml 文件学习~

Mybatis 源码之pom.xml 文件学习~

作者: 相关知情人士 | 来源:发表于2017-04-23 10:18 被阅读0次

    前言

    研读Mybatis源码之前,或者一个项目之前,我选择了先看一下项目管理配置文件,有个整体的总揽,同时也可以学习一下此类框架软件的写法及一些常用操作,同时理解一个完整开源框架需要哪些非编程语言相关的知识,Mybatis还有 parent-pom文件,非常的长,以后有机会希望自己慢慢的能用gradle实现同样的功能~


    Xml如下,添加了一些标签的解释.参考史上最全maven pom文件标签详解,一些依赖和插件也要自己动手查查看,慢慢积累~(简书引用代码如何做到自动换行?目前没有找到方法,有知道的可以留言一下,若影响阅读体验可以把文本复制出去看..)

    <?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><!--声明项目描述符遵循哪一个POM模型版本。模型本身的版本很少改变,虽然如此,但它仍然是必不可少的,这是为了当Maven引入了新的特性或者其他模型变更的时候,确保稳定性。-->  
    
      <parent>  <!--父项目的坐标。如果项目中没有规定某个元素的值,那么父项目中的对应值即为项目的默认值。 坐标包括group ID,artifact ID和 version。-->
        <!--被继承的父项目的构件标识符-->
        <groupId>org.mybatis</groupId><!--被继承的父项目的全球唯一标识符-->
        <artifactId>mybatis-parent</artifactId><!--被继承的父项目的构件标识符-->
        <version>28</version><!--被继承的父项目的版本-->
        <relativePath /><!-- 父项目的pom.xml文件的相对路径。相对路径允许你选择一个不同的路径。默认值是../pom.xml。Maven首先在构建当前项目的地方寻找父项 目的pom,其次在文件系统的这个位置(relativePath位置),然后在本地仓库,最后在远程仓库寻找父项目的pom。-->
      </parent>
      <!--项目的全球唯一标识符,通常使用全限定的包名区分该项目和其他项目。并且构建时生成的路径也是由此生成, 如com.mycompany.app生成的相对路径为:/com/mycompany/app-->
      <!--mybattis的groupId应该和父项目的一致,所以这里没这个标签</groupId>-->
      <artifactId>mybatis</artifactId><!-- 构件的标识符,它和group ID一起唯一标识一个构件。换句话说,你不能有两个不同的项目拥有同样的artifact ID和groupID;在某个 特定的group ID下,artifact ID也必须是唯一的。构件是项目产生的或使用的一个东西,Maven为项目产生的构件包括:JARs,源 码,二进制发布和WARs等。-->
      <version>3.4.5-SNAPSHOT</version><!--项目当前版本,格式为:主版本.次版本.增量版本-限定版本号-->
      <packaging>jar</packaging><!--项目产生的构件类型,例如jar、war、ear、pom。插件可以创建他们自己的构件类型,所以前面列的不是全部构件类型-->
    
      <name>mybatis</name><!--项目的名称, Maven产生的文档用-->
      <description><!-- 项目的详细描述, Maven 产生的文档用。  当这个元素能够用HTML格式描述时(例如,CDATA中的文本会被解析器忽略,就可以包含HTML标 签), 不鼓励使用纯文本描述。如果你需要修改产生的web站点的索引页面,你应该修改你自己的索引页文件,而不是调整这里的文档。-->
        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> <!--项目主页的URL, Maven产生的文档用-->
    
      <inceptionYear>2009</inceptionYear><!--项目创建年份,4位数字。当产生版权信息时需要使用这个值。-->
    
      <contributors><!--项目的其他贡献者列表-->
        <contributor><!--项目的其他贡献者。参见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)标签允许你配置你的代码库,供Maven web站点和其它插件使用。-->
        <url>http://github.com/mybatis/mybatis-3</url><!--指向项目的可浏览SCM库(例如ViewVC或者Fisheye)的URL。-->
        <connection>scm:git:ssh://github.com/mybatis/mybatis-3.git</connection><!--SCM的URL,该URL描述了版本库和如何连接到版本库。欲知详情,请看SCMs提供的URL格式和列表。该连接只读。-->
        <developerConnection>scm:git:ssh://git@github.com/mybatis/mybatis-3.git</developerConnection><!--给开发者使用的,类似connection元素。即该连接不仅仅只读-->
        <tag>HEAD</tag><!--当前代码的标签,在开发阶段默认为HEAD-->
      </scm>
      <issueManagement> <!--项目的问题管理系统(Bugzilla, Jira, Scarab,或任何你喜欢的问题管理系统)的名称和URL-->
        <system>GitHub Issue Management</system><!--问题管理系统的名字,-->
        <url>https://github.com/mybatis/mybatis-3/issues</url><!--该项目使用的问题管理系统的URL-->
      </issueManagement>
      <ciManagement><!--项目持续集成信息-->
        <system>Travis CI</system><!--持续集成系统的名字,例如continuum-->
        <url>https://travis-ci.org/mybatis/mybatis-3/</url><!--该项目使用的持续集成系统的URL(如果持续集成系统有web接口的话)。-->
      </ciManagement>
      <distributionManagement><!--项目分发信息,在执行mvn deploy后表示要发布的位置。有了这些信息就可以把网站部署到远程服务器或者把构件部署到远程仓库。-->
        <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可以在整个POM中使用,也可以作为触发条件(见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><!-- 继承自该项目的所有子项目的默认依赖信息。这部分的依赖信息不会被立即解析,而是当子项目声明一个依赖(必须描述group ID和 artifact ID信息),如果group ID和artifact ID以外的一些信息没有描述,则通过group ID和artifact ID 匹配到这里的依赖,并使用这里的依赖信息。-->
        <!--好多的依赖可以自行百度一下简介,我感受有2点,1是 mybatis好像并没有依赖于太多的第三方库,2是 测试用的依赖涉及到了一些,单元测试等等的水还是非常之深的~  -->
        <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><!--构建项目需要的信息-->
        <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可使用操作系统信息,jdk信息,文件是否存在,属性值等作为依据,来激活相应的profile,也可在编译阶段,通过mvn命令加参数 -PprofileId 来手工激活使用对应的profile-->
        <!--结合filter和profile,我们就可以方便的在不同环境下使用不同的配制-->
        <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>
    
    

    相关文章

      网友评论

          本文标题:Mybatis 源码之pom.xml 文件学习~

          本文链接:https://www.haomeiwen.com/subject/bogezttx.html