Shellbye.github.io icon indicating copy to clipboard operation
Shellbye.github.io copied to clipboard

《Maven 实战》读书笔记

Open Shellbye opened this issue 5 years ago • 0 comments


第 1 章 Maven 简介
    1.1 何为 Maven
        1.1.1 何为构建
        1.1.2 Maven 是优秀的构建工具
        1.1.3 Maven 不仅仅是构建工具
            约定优于配置 Convention over Configuration
    1.2 为什么需要 Maven
        1.2.1 组装 PC 和品牌 PC 
        1.2.2 IDE 不是万能的
        1.2.3 Make
        1.2.4 Ant
        1.2.5 不重复发明轮子
    1.3 Maven 与极限编程
    1.4 被误解的 Maven
    1.5 小结

第 2 章 Maven 的安装与配置
    2.1 在 Windows 上安装
    2.2 在基于 UNIX 的系统上安装 Maven
    2.3 安装目录分析
        2.3.1 M2_HOME
        2.3.2 ~/.m2/
    2.4 设置 HTTP 代理
    2.5 安装 m2eclipse
    2.6 安装 NetBeans Maven 插件
    2.7 Maven 安装最佳实践
        2.7.1 设置 MAVEN_OPTS 环境变量
        2.7.2 配置用户范围 settings.xml
        2.7.3 不要使用 IDE 内置的 Maven
    2.8 小结

第 3 章 Maven 使用入门
    3.1 编写 POM
        Project Object Model
        project 
            是所有 pom.xml 的
        modelVersion
            对于 Maven2 和 Maven3 只能是 4.0.0
    3.2 编写主代码
        mvn clean compile 
    3.3 编写测试代码
        mvn clean test
        由于历史原因, Maven 的核心插件之一 compiler 插件默认只支持编译 Java 1.3,
        因此需要配置该插件使其支持其他版本的 Java 
        <project>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <configuration>
                            <source>8</source>
                            <target>8</target>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </project>
    3.4 打包和运行
        mvn clean package
        mvn clean install
        命名规则
            artifact-version.jar
        默认生成的 jar 是不能直接运行的,为了生成可执行的 jar 文件,
        需要借助 maven-shade-plugin
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.2.1</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>com.example.to.MainClass</mainClass>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    3.5 使用 Archetype 生成项目骨架
        mvn archetype:generate
    3.6 m2eclipse 简单使用
        略
    3.7 NetBeans Maven 插件简单使用
        略
    3.8 小结

第 4 章 背景案例
    4.1 简单的账户注册服务
    4.2 需求阐述
    4.3 简要设计
    4.4 小结

第 5 章 坐标和依赖
    5.1 何为 Maven 坐标
        groupId 
        artifactId
        version
        packaging
        classifier
    5.2 坐标详解
        groupId 
            当前项目隶属的实际项目
        artifactId
            模块
        version
            版本
        packaging
            打包方式
        classifier
            定义构建输出的一些附属构件
    5.3 account-email
    5.4 依赖的配置
        <project>
            <dependencies>
                <dependency>
                    <groupId>group-a</groupId>
                    <artifactId>artifact-a</artifactId>
                    <version>1.0</version>
                    <type></type>
                    <scope></scope>
                    <optional></optional>
                    <exclusions>
                        <exclusion>
                            <groupId>group-c</groupId>
                            <artifactId>excluded-artifact</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
            </dependencies>
        </project>
    5.5 依赖范围
        compile 
        test
        provided
            servlet-api, 编译和测试项目时需要,但是运行时,由于容器已经提供,就不需要引入了
        runtime
            jdbc
        system
        import
    5.6 传递性依赖
        5.6.1 何为传递性依赖
        5.6.2 传递性依赖和依赖范围
    5.7 依赖调解
        第一原则
            路径最近者优先
        第二原则
            第一声明者优先
    5.8 可选依赖
    5.9 最佳实践
        5.9.1 排除依赖
        5.9.2 归类依赖
        5.9.3 优化依赖
    5.10 小结

第 6 章 仓库
    6.1 何为 Maven 仓库
    6.2 仓库的布局
    6.3 仓库的分类
        本地仓库
        远程仓库
            中央仓库
            私服
            其他公共库
        6.3.1 本地仓库
            ~/.m2/repository/
            <settings>
                <localRepository>path/to/dir/</localRepository>
            </settings>
        6.3.2 远程仓库
        6.3.3 中央仓库
            <repositories>
                <repository>
                    <id>central</id>
                    <name>Maven repository switchboard</name>
                    <url>http://repo1.maven.com/maven2</url>
                    <layout>default</layout>
                    <snapshotPolicy>always</snapshotPolicy>
                </repository>
            </repositories>
        6.3.4 私服
    6.4 远程仓库的配置
        6.4.1 远程仓库的认证
            <servers>
                <server>
                    <id>deploymentRepo</id>
                    <username>repouser</username>
                    <password>repopwd</password>
                </server>
            </servers>
        6.4.2 部署至远程仓库
            <distributionManagement>
                <repository>
                    <id>releases</id>
                    <url>http://www.domain.com/nexus/content/repositories/releases/</url>
                </repository>
                <snapshotRepository>
                    <id>snapshots</id>
                    <url>http://www.domain.com/nexus/content/repositories/snapshots/</url>
                </snapshotRepository>
            </distributionManagement>
    6.5 快照版本
    6.6 从仓库解析依赖的机制
    6.7 镜像
        <mirrors>
            <mirror>
                <id>mirrorId</id>
                <mirrorOf>repositoryId</mirrorOf>
                <name>Human Readable Name for this Mirror.</name>
                <url>http://my.repository.com/repo/path</url>
            </mirror>
        </mirrors>
    6.8 仓库搜索服务
        6.8.1 Sonatype Nexus 
        6.8.2 Jarvana
        6.8.3 MVNbrower
        6.8.4 MVNrepository
    6.9 小结

第 7 章 生命周期和插件
    7.1 何为生命周期
    7.2 生命周期详解
        7.2.1 三套生命周期
        7.2.2 clean 生命周期
            pre-clean
            clean
            post-clean
        7.2.3 default 生命周期
            validate
            initialize
            generate-sources
            process-sources 
            generate-resources 
            process-resources 
            compile 
            process-classes
            generate-test-sources 
            process-test-sources
            generate-test-resources
            process-test-resources
            test-compile 
            process-test-classes 
            test
            prepare-package 
            package 
            pre-integration-test 
            integration-test
            post-integration-test
            verify
            install
            deploy
        7.2.4 site 生命周期
            pre-site
            site
            post-site 
            site-deploy 
        7.2.5 命令行与生命周期
    7.3 插件目标
    7.4 插件绑定
        7.4.1 内置绑定
        7.4.2 自定义绑定
            创建源码 jar 包
                <project>
                    <build>
                        <plugins>
                            <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-source-plugin</artifactId>
                                <version>2.1.1</version>
                                <executions>
                                    <exclusion>
                                        <id>attach-sources</id>
                                        <phase>verify</phase>
                                        <goals>
                                            <goal>jar-no-fork</goal>
                                        </goals>
                                    </execution>
                                </executions
                            </plugin>
                        </plugins>
                    </build>
                </project>
    7.5 插件配置
        7.5.1 命令行插件配置
            mvn install -Dmaven.test.skip=true
        7.5.2 POM 中插件全局配置
                <build>
                    <plugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-compiler-plugin</artifactId>
                            <configuration>
                                <source>8</source>
                                <target>8</target>
                            </configuration>
                        </plugin>
                    </plugins>
                </build>
        7.5.3 POM 中插件任务配置
    7.6 获取插件信息
    7.7 从命令行调用插件
    7.8 插件解析机制
        7.8.1 插件仓库
            pluginRepositories
第8章 聚合与继承
    8.2 聚合
        <modules>
            <module>xx</module>
        </modules>
    8.3 继承
        <parent>
            <groupId>xx</groupId>
        </parent>

        8.3.3 依赖管理
            避免不需要相应依赖的子模块被迫继承
            <dependencyManagement>
            </dependencyManagement>
        8.3.4 插件管理
            <pluginManagement>
            </pluginManagement>

略

Shellbye avatar Sep 29 '19 03:09 Shellbye