更新Maven POM文件中依赖库的版本

维护一个Maven管理的Java项目的时候,有的时候需要更新项目依赖的第三方的库,比如将Spring 3.2.16升级成Spring 4.2.5。我们可以通过Maven versions插件自动化的实现。

这个插件定义了非常多的goal:

  • versions:compare-dependencies compares the dependency versions of the current project to the dependency management section of a remote project.
  • versions:display-dependency-updates scans a project's dependencies and produces a report of those dependencies which have newer versions available.
  • versions:display-plugin-updates scans a project's plugins and produces a report of those plugins which have newer versions available.
  • versions:display-property-updates scans a projectand produces a report of those properties which are used to control artifact versions and which properies have newer versions available.
  • versions:update-parent updates the parent section of a project so that it references the newest available version. For example, if you use a corporate root POM, this goal can be helpful if you need to ensure you are using the latest version of the corporate root POM.
  • versions:update-properties updates properties defined in a project so that they correspond to the latest available version of specific dependencies. This can be useful if a suite of dependencies must all be locked to one version.
  • versions:update-property Sets a property to the latest version in a given range of associated artifacts.
  • versions:update-child-modules updates the parent section of the child modules of a project so the version matches the version of the current project. For example, if you have an aggregator pom that is also the parent for the projects that it aggregates and the children and parent versions get out of sync, this mojo can help fix the versions of the child modules. (Note you may need to invoke Maven with the -N option in order to run this goal if your project is broken so badly that it cannot build because of the version mis-match).
  • versions:lock-snapshots searches the pom for all -SNAPSHOT versions and replaces them with the current timestamp version of that -SNAPSHOT, e.g. -20090327.172306-4
  • versions:unlock-snapshots searches the pom for all timestamp locked snapshot versions and replaces them with -SNAPSHOT.
  • versions:resolve-ranges finds dependencies using version ranges and resolves the range to the specific version being used.
  • versions:set can be used to set the project version from the command line.
  • versions:use-releases searches the pom for all -SNAPSHOT versions which have been released and replaces them with the corresponding release version.
  • versions:use-next-releases searches the pom for all non-SNAPSHOT versions which have been a newer release and replaces them with the next release version.
  • versions:use-latest-releases searches the pom for all non-SNAPSHOT versions which have been a newer release and replaces them with the latest release version.
  • versions:use-next-snapshots searches the pom for all non-SNAPSHOT versions which have been a newer -SNAPSHOT version and replaces them with the next -SNAPSHOT version.
  • versions:use-latest-snapshots searches the pom for all non-SNAPSHOT versions which have been a newer -SNAPSHOT version and replaces them with the latest -SNAPSHOT version.
  • versions:use-next-versions searches the pom for all versions which have been a newer version and replaces them with the next version.
  • versions:use-latest-versions searches the pom for all versions which have been a newer version and replaces them with the latest version.
  • versions:commit removes the pom.xml.versionsBackup files. Forms one half of the built-in "Poor Man's SCM".
  • versions:revert restores the pom.xml files from the pom.xml.versionsBackup files. Forms one half of the built-in "Poor Man's SCM".

也提供了三个reporting goal:

  • versions:dependency-updates-report produces a report of those project dependencies which have newer versions available.
  • versions:plugin-updates-report produces a report of those plugins which have newer versions available.
  • versions:property-updates-report produces a report of those properties which are used to control artifact versions and which properies have newer versions available.

如果你的项目中artifact的版本都是通过属性定义的,那么mvn versions:display-property-updates可以在命令行中显示可以更新的依赖的信息。

你可以手工更改这些依赖的版本,也可以通过mvn versions:update-properties自动更新定义版本的属性。

上面的命令会为你原始的pom.xml产生一个备份文件,如果没有更新问题,你可以通过 mvn versions:commit移除这个备份文件。

在Go web服务器中实现prefork和affinity

Apache服务器可是使用prefork技术,启动多个独立的进程,每个进程独立的处理http请求,不需要担心线程安全的问题。

This Multi-Processing Module (MPM) implements a non-threaded, pre-forking web server that handles requests in a manner similar to Apache 1.3. It is appropriate for sites that need to avoid threading for compatibility with non-thread-safe libraries. It is also the best MPM for isolating each request, so that a problem with a single request will not affect any other.

尽管prefork在处理高并发的情况下并不高效,但是作为一个技术,倒是有启发我们的地方。我最近在调研Go服务器的性能看到一段代码,很优雅的实现了prefork和affinity的的功能,特地抄写在本文中,看看他是怎么实现的。

阅读全文

巅峰对决 - 框架的性能比较

天下武功,无坚不摧,无快不破

这句话也可以应用在软件开发上,"无快不破"强调的是软件的性能。我陆陆续续写了多篇各种框架的文章,也在github上开了多个性能比较的开源项目,本文做一个汇总,以备将来的查找。

阅读全文

Scala native即将发布

洛桑联邦理工学院(EPFL)发布了一个新的网站http://www.scala-native.org/,他们宣布了一个新的项目 Scala Native,但是没有公布具体的内容,只有"coming soon"的提示, 但是网站上唯一的提示 "Your favourite language gets closer to bare metal." 隐约透漏它可能是可以使用Scala编程语言编译成本机代码的项目。

Scala除了纵向发展外(Scala本身语言的扩展), 也在横向的发展, 比如Scala.js将Scala语言引入到Javascript中,它可以将Scala语言编译成javascript。因此有理由相信,这个即将发布的项目可以将Scala代码编译成本机代码,这样就可以脱离虚拟机直接运行了。

阅读全文

使用visual studio code开发Go程序

在visual studio code 1.0发布之前我也曾多次尝试使用visual studio code开发Go程序,但是都放弃了,一是Go的插件还没发布或者不完善,而是vscode还不是那么方便,所以我一直使用atom + goplus + godebug编写Go的代码,而且用起来也非常的顺手方便。 现在vscode 1.0发布了,而且支持10种本地化语言,我尝试使用它编写Go程序,功能和性能都不错,所以目前atom和vscode都是我的菜。

本文简单介绍一下使用vscode开发Go的一些配置,速览vscode + Go 的功能。

阅读全文

Go Channel 详解

Channel是Go中的一个核心类型,你可以把它看成一个管道,通过它并发核心单元就可以发送或者接收数据进行通讯(communication)。

它的操作符是箭头 <-

1
2
ch <- v // 发送值v到Channel ch中
v := <-ch // 从Channel ch中接收数据,并将数据赋值给v

(箭头的指向就是数据的流向)

就像 map 和 slice 数据类型一样, channel必须先创建再使用:

1
ch := make(chan int)

阅读全文

Go泛型提案

Go泛型特性已经被讨论了多次了1, Andrew Gerrand现在把这个提案加入到了Go的issue列表中2,并标记为Go2标签。当然这不代表着要将泛型加入到Go中,而是演示一个完整的提案应该是什么样子。

阅读全文

使用Golang实现Futures 和 Promises

其它语言中Future和Promise的概念大量存在, 比如Node.js、Scala、Java、C#、C++ 11、Scheme、Swift等,可以方便的实现异步执行和回调。但是在Go语言的世界里,我们是通过goroutine/channel实现这种类似的功能呢,goroutine之间可以通过channel进行通讯, 但是,如果我们还是想使用Future/Promise的功能的话,该如何实现呢?

Future,Promise或Delay是用于并发编程的一种设计模式。它们表示一个对象,这个对象用来作为一次计算结果的代理,而该结果开始的时候是未知的,因为计算还没有完成。Promise与Future的区别在于,Future是Promise的一个只读的视图,也就是说Future没有设置任务结果的方法,只能获取任务执行结果或者为Future添加回调函数。

阅读全文