java svn 版本号_java – 如何使用SVN和Maven获取内部版本号?

我使用buildnumber-maven-plugin,我需要从svn获取构建数量的项目.我的pom.xml:

scm:svn:https://username:password@path_to_repositiry

org.codehaus.mojo

buildnumber-maven-plugin

1.1

validate

create

false

false

javasvn

com.google.code.maven-scm-provider-svnjava

maven-scm-provider-svnjava

2.0.2

org.tmatesoft.svnkit

svnkit

1.7.4-v1

但是当我打包一个项目时,我有错误:

[ERROR] Failed to execute goal org.codehaus.mojo:buildnumber-maven-plugin:1.1:create (default)on project myproject: Cannot get the revision information from the scm repository : [ERROR] Exception while executing SCM command. svn: E155021: This client is too old to work with the working copy at [ERROR] 'D:\projects\myproject' (format {1}).

虽然我使用TortoiseSVN 1.8.2!

我读到使用TortoiseSVN 1.7及更早版本的buildnumber-maven-plugin表现得如此.

如何使用SVN和Maven获取内部版本号?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以使用 SVNKit 库来实现 Java 获取 SVN 两个版本号之间的提交记录和对应的文件路径。 首先,你需要引入 SVNKit 库,可以通过 Maven 进行引入: ```xml <dependency> <groupId>org.tmatesoft.svnkit</groupId> <artifactId>svnkit</artifactId> <version>1.10.1</version> </dependency> ``` 接下来,你可以使用以下代码来获取 SVN 两个版本号之间的提交记录和对应的文件路径: ```java import org.tmatesoft.svn.core.*; import org.tmatesoft.svn.core.io.SVNRepository; import org.tmatesoft.svn.core.io.SVNRepositoryFactory; import org.tmatesoft.svn.core.wc.SVNRevision; import java.util.ArrayList; import java.util.List; public class SVNUtil { public static List<SVNLogEntry> getLogEntries(String url, long startRevision, long endRevision) throws SVNException { List<SVNLogEntry> logEntries = new ArrayList<>(); SVNURL svnurl = SVNURL.parseURIEncoded(url); SVNRepository repository = SVNRepositoryFactory.create(svnurl); repository.setAuthenticationManager(SVNWCUtil.createDefaultAuthenticationManager()); repository.log(new String[]{""}, null, startRevision, endRevision, true, true, 1000, new ISVNLogEntryHandler() { @Override public void handleLogEntry(SVNLogEntry svnLogEntry) throws SVNException { logEntries.add(svnLogEntry); } }); return logEntries; } public static List<String> getChangedPaths(String url, long startRevision, long endRevision) throws SVNException { List<String> changedPaths = new ArrayList<>(); SVNURL svnurl = SVNURL.parseURIEncoded(url); SVNRepository repository = SVNRepositoryFactory.create(svnurl); repository.setAuthenticationManager(SVNWCUtil.createDefaultAuthenticationManager()); repository.log(new String[]{""}, null, startRevision, endRevision, true, true, 1000, new ISVNLogEntryHandler() { @Override public void handleLogEntry(SVNLogEntry svnLogEntry) throws SVNException { for (Object o : svnLogEntry.getChangedPaths().keySet()) { SVNLogEntryPath entryPath = (SVNLogEntryPath) svnLogEntry.getChangedPaths().get(o); changedPaths.add(entryPath.getPath()); } } }); return changedPaths; } public static void main(String[] args) throws SVNException { String url = "svn://svnserver/repository"; long startRevision = 1000; long endRevision = 2000; List<SVNLogEntry> logEntries = getLogEntries(url, startRevision, endRevision); for (SVNLogEntry logEntry : logEntries) { System.out.println(logEntry.getMessage()); } List<String> changedPaths = getChangedPaths(url, startRevision, endRevision); for (String changedPath : changedPaths) { System.out.println(changedPath); } } } ``` 在上述代码中,`getLogEntries` 方法用于获取提交记录,`getChangedPaths` 方法用于获取对应的文件路径。你需要传入 SVN 仓库的 URL、起始版本号和结束版本号来调用这些方法。获取的提交记录和文件路径将以列表的形式返回。 注意,在使用 `SVNRepository` 对象时需要设置认证管理器,这里使用的是默认的认证管理器。 同时,你需要在代码中引用以下包: ```xml <dependency> <groupId>org.tmatesoft.sqljet</groupId> <artifactId>sqljet</artifactId> <version>1.1.10</version> </dependency> <dependency> <groupId>org.tmatesoft.svnkit</groupId> <artifactId>svnkit-javahl16</artifactId> <version>1.10.1</version> </dependency> <dependency> <groupId>org.tmatesoft.svnkit</groupId> <artifactId>svnkit-cli</artifactId> <version>1.10.1</version> </dependency> ``` 注意,这里使用的是 `svnkit-javahl16` 和 `svnkit-cli`,因为这些库在 Windows 平台上比较稳定。如果你在其他平台上运行代码,可以考虑使用其他版本SVNKit 库。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值