maven 发布test jar
很多时候我们自己开发了一个框架(比如查询引擎),框架自身测试比较复杂(依赖不少核心,而且组件比较多)
同时我们也是暴露core 让别的开发者可以很好的测试,此时我们可能就需要暴露一个test jar 了(比如dremio等一些重量级的平台工具)
实际上暴露test jar 以及发布test jar 的方法比较简单
参考demo
- 代码结构
├── pom.xml
└── src
├── main
│ ├── java
│ │ └── com
│ │ └── dalong
│ │ └── UserLogin.java
│ └── resources
└── test
└── java
└── com
└── dalong
└── TestUserLogin.java
- 参考pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>com.dalong</groupId>
<artifactId>testpacakge</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
deploy
注意目前是没有发现类似直接可以通过maven deploy test jar 包的,解决方法是通过mvn deploy:deploy-file 解决
参考
mvn deploy:deploy-file -Durl=file://C:\m2-repo \
-DrepositoryId=some.id \
-Dfile=your-artifact-1.0.jar \
[-DpomFile=your-pom.xml] \
[-DgroupId=org.some.group] \
[-DartifactId=your-artifact] \
[-Dversion=1.0] \
[-Dpackaging=jar] \
[-Dclassifier=test] \
[-DgeneratePom=true] \
[-DgeneratePom.description="My Project Description"] \
[-DrepositoryLayout=legacy]
使用
参考如下:推荐type 以及classifier 都加上
<dependency>
<groupId>com.dalong</groupId>
<artifactId>testpacakge</artifactId>
<version>1.0-SNAPSHOT</version>
<classifier>tests</classifier>
<type>test-jar</type>
<scope>test</scope>
</dependency>
说明
以上默认的模式是有一些问题的,比如test 的依赖传递,实际上maven 官方推荐是将test 代码放到src/main/java 中,对于jar 使用一个test 命名
同时对于依赖test 包的项目添加scope 为test,比如dremio 的test 包就存在类似的问题,它在处理test 包的时候就使用了类似的方法,但是对于test 包
处理上传了,目前暂时还没找到比较好的方法,如果真的需要将test 包共享,推荐还是参考官方的模式(创建独立的jar)
参考资料
https://maven.apache.org/plugins/maven-jar-plugin/examples/create-test-jar.html
https://maven.apache.org/pom.html
https://maven.apache.org/plugins/maven-deploy-plugin/usage.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
2020-02-28 hasura graphql-engine ha 以及自动缩放的一些参考资料
2020-02-28 hasura graphql-engine v1.2.0 beta 版本
2020-02-28 postgres http fdw + plv8+pg_cron 处理数据
2019-02-28 ClusterControl docker 环境搭建
2019-02-28 验证远程主机SSH指纹
2018-02-28 grpc gateway 使用以及docker compose 集成