【飞天奔月出品】使用Maven打all-in-one的包(带tests 和 sources)(多方案实现对比)

1.痛点

feilong-spring 项目子项目很多

使用 Maven依赖的话,要写很多代码

<project>

    ....
    <properties>
        <version.feilong-platform>1.9.6</version.feilong-platform>
        ....
    </properties>

    ....
    <repositories>
        <repository>
            <id>feilong-repository</id>
            <url>https://raw.github.com/venusdrogon/feilong-platform/repository</url>
        </repository>
    </repositories>

    ....
    <dependencies>
        ....
        <dependency>
            <groupId>com.feilong.platform.spring</groupId>
            <artifactId>feilong-spring-core</artifactId>
            <version>${version.feilong-platform}</version>
        </dependency>
        <dependency>
            <groupId>com.feilong.platform.spring</groupId>
            <artifactId>feilong-spring-aop</artifactId>
            <version>${version.feilong-platform}</version>
        </dependency>
        <dependency>
            <groupId>com.feilong.platform.spring</groupId>
            <artifactId>feilong-spring-context</artifactId>
            <version>${version.feilong-platform}</version>
        </dependency>
        <dependency>
            <groupId>com.feilong.platform.spring</groupId>
            <artifactId>feilong-spring-jdbc</artifactId>
            <version>${version.feilong-platform}</version>
        </dependency>
        <dependency>
            <groupId>com.feilong.platform.spring</groupId>
            <artifactId>feilong-spring-web</artifactId>
            <version>${version.feilong-platform}</version>
        </dependency>
        ....
    </dependencies>

    ....

</project>

能否做个 all-in-one 的jar(such as quartz-all,netty-all) ,只需要依赖这一个jar 即可?

2.解决方案

2.1 方案1:将所有的项目合并成一个项目

调整项目结构,类似于 feilong taglib issues1 ,但是 feilong-spring 不适合 ,文件太杂,维护起来很困难

image

2.2 方案2:使用 maven-antrun-plugin 插件

在我百思不得其解的时候,想起"咦,别人是怎么做的?",此时 github 开源的力量是无穷的,我查阅了 quartz-all

他使用了 maven-antrun-plugin 插件, 我借鉴并修改成以下一版 pom.xml

<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>
	<parent>
		<groupId>com.feilong.platform.spring</groupId>
		<artifactId>parent</artifactId>
		<version>1.10.0-SNAPSHOT</version>
	</parent>

	<artifactId>feilong-spring-all</artifactId>
	<packaging>jar</packaging>

	<build>
		<plugins>
			<plugin>
				<artifactId>maven-antrun-plugin</artifactId>
				<executions>
					<execution>
						<id>packing-all</id>
						<phase>process-sources</phase>
						<configuration>
							<tasks>
								<copy todir="${project.build.directory}/classes">
									<fileset dir="${basedir}/../feilong-spring-aop/target/classes" />
									<fileset dir="${basedir}/../feilong-spring-context/target/classes" />
									<fileset dir="${basedir}/../feilong-spring-core/target/classes" />
									<fileset dir="${basedir}/../feilong-spring-jdbc/target/classes" />
									<fileset dir="${basedir}/../feilong-spring-mobile/target/classes" />
									<fileset dir="${basedir}/../feilong-spring-web/target/classes" />
								</copy>
							</tasks>
						</configuration>
						<goals>
							<goal>run</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</project>

2.2.1 依赖结果

随便找个项目,依赖下测试

<dependencies>
	...
	<dependency>
		<groupId>com.feilong.platform.spring</groupId>
		<artifactId>feilong-spring-all</artifactId>
		<version>1.10.0-SNAPSHOT</version>
	</dependency>
	...
</dependencies>

显示:

image

2.2.2 缺点:

没有source 以及 test 包

image

不利于查看javadoc 以及学习

2.3 方案3: 使用 maven-assembly-plugin插件

那么我们继续寻找其他方案, 咦,发现 shiro-all 在仓库中有 pom.xml

image

他是怎么做到的呢?

查看下他的源码 , 可以看到他使用了 maven-assembly-plugin 插件

pom.xml

<plugins>
	<plugin>
		<artifactId>maven-assembly-plugin</artifactId>
		<executions>
			<execution>
				<id>make-bundles</id>
				<goals>
					<goal>single</goal>
				</goals>
				<phase>package</phase>
				<!---->
				<configuration>
					<descriptors>
						<descriptor>src/main/assembly/assembly.xml</descriptor>
					</descriptors>

					<!-- We _do_ want the assembly output to be the actual artifact produced for this Maven module. -->
					<!-- not append assembly id in release file name -->
					<appendAssemblyId>false</appendAssemblyId>
				</configuration>
			</execution>
		</executions>
	</plugin>
</plugins>

assembly.xml

<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">

	<id>jar</id>
	
	<formats>
		<format>jar</format>
	</formats>
	
	<includeBaseDirectory>false</includeBaseDirectory>
	
	<dependencySets>
		<dependencySet>
			<outputDirectory>/</outputDirectory>
			<useProjectArtifact>false</useProjectArtifact>
			<unpack>true</unpack>
			<useTransitiveDependencies>false</useTransitiveDependencies>
		</dependencySet>
	</dependencySets>

</assembly>
2.3.1 缺点:

依赖 feilong-spring-all jar, 项目还会自动依赖 feilong-spring-all 所依赖的jar

image

image

shiro-all 1.4.0-RC2 写法也一样不行

image

重复依赖很明显

2.4 方案4: 使用 maven-shade-plugin 插件

shiro-all 1.3.2 支持 sources image

并且依赖之后,没有明显的重复依赖 :thumbsup: (This is what i want what i really really want)

image

shiro-all 1.3.2 系列使用的maven-shade-plugin 插件

image

2.4.1 feilong-spring-all 配置

feilong-spring-all pom.xml 配置如下


<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>

	<parent>
		<groupId>com.feilong.platform.spring</groupId>
		<artifactId>parent</artifactId>
		<version>1.10.0-SNAPSHOT</version>
	</parent>

	<artifactId>feilong-spring-all</artifactId>
	<packaging>jar</packaging>

	<properties>
		<v.maven-shade-plugin>2.4.3</v.maven-shade-plugin>
	</properties>

	<dependencies>

		<dependency>
			<groupId>com.feilong.platform.spring</groupId>
			<artifactId>feilong-spring-aop</artifactId>
			<version>${project.version}</version>
		</dependency>

		<dependency>
			<groupId>com.feilong.platform.spring</groupId>
			<artifactId>feilong-spring-context</artifactId>
			<version>${project.version}</version>
		</dependency>

		<dependency>
			<groupId>com.feilong.platform.spring</groupId>
			<artifactId>feilong-spring-core</artifactId>
			<version>${project.version}</version>
		</dependency>

		<dependency>
			<groupId>com.feilong.platform.spring</groupId>
			<artifactId>feilong-spring-jdbc</artifactId>
			<version>${project.version}</version>
		</dependency>

		<dependency>
			<groupId>com.feilong.platform.spring</groupId>
			<artifactId>feilong-spring-mobile</artifactId>
			<version>${project.version}</version>
		</dependency>

		<dependency>
			<groupId>com.feilong.platform.spring</groupId>
			<artifactId>feilong-spring-web</artifactId>
			<version>${project.version}</version>
		</dependency>

	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-shade-plugin</artifactId>
				<version>${v.maven-shade-plugin}</version>
				<executions>
					<execution>
						<phase>package</phase>
						<goals>
							<goal>shade</goal>
						</goals>
						<configuration>
							<!-- With version 2.2 of the maven-shade-plugin, they added a "shadeTestJar" option (see MSHADE-158): http://maven.apache.org/plugins/maven-shade-plugin/shade-mojo.html#shadeTestJar -->
							<shadeTestJar>true</shadeTestJar>
							<!-- When true, it will attempt to create a sources jar as well -->
							<createSourcesJar>true</createSourcesJar>

							<artifactSet>
								<includes>
									<include>${project.groupId}:*:*</include>
								</includes>
							</artifactSet>

						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</project>

配置方式中增加了两个属性参数:

2.4.2 feilong-spring-all deploy之后的情况

参见 https://github.com/venusdrogon/feilong-platform/tree/repository/com/feilong/platform/spring/feilong-spring-all/1.10.0-SNAPSHOT

image

可以看到 pom.xml ,jar,sources jar,tests jar 一应齐全,棒棒哒 :clap:

2.4.3 feilong-spring-all 被依赖情况

很完美,做到了只依赖feilong-spring-all,并且不再依赖 feilong-spring-all 自身依赖的jar

搞定,收工~~

3.参考

----完

转载于:https://my.oschina.net/venusdrogon/blog/809186

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Netty是由JBOSS提供的一个java开源框架。Netty提供异步的、事件驱动的网络应用程序框架和工具,用以快速开发高性能、高可靠性的网络服务器和客户端程序dsf。 也就是说,Netty 是一个基于NIO的客户,服务器端编程框架,使用Netty 可以确保你快速和简单的开发出一个网络应用,例如实现了某种协议的客户,服务端应用。Netty相当简化和流线化了网络应用的编程开发过程,例如,TCP和UDP的socket服务开发。 “快速”和“简单”并不意味着会让你的最终应用产生维护性或性能上的问题。Netty 是一个吸收了多种协议的实现经验,这些协议括FTP,SMTP,HTTP,各种二进制,文本协议,并经过相当精心设计的项目,最终,Netty 成功的找到了一种方式,在保证易于开发的同时还保证了其应用的性能,稳定性和伸缩性。 从之前发布其他chm文件下载用户的反映看,有不少朋友反映下载后打开无法显示,这一般不是chm文件的问题,这里统一说明一下解决办法: 如果文件打开看不到右边的内容,是因为你的操作系统为了安全对下载的chm文件进行了锁定,只需要在打开前右键单击该chm文件选择“属性”,然后在“常规”选项卡的下方单击“解除锁定”按钮就可以了。如果还是不能看,请再查看一下你的chm文件所存储的目录或文件名是否有特殊字符如“#”号字符等,去掉特殊字符即可。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值