Should @version tag denote the version of the artifact this source file is a part of, or the version when this file was last changed?

时间:2015-07-28 23:19:13

标签: java version javadoc

Previously my understanding was that the purpose of the @version tag was to show to library users in which release a particular file was last changed. For example, if there is a new release for liblibrary v1.7, and its developers maintain @version tags in sources in actual state (either manually or with an automated tool), then one could look at the sources artifact and see whether that particular file has changed since previous version 1.6.

But here is a piece of documentation for javadoc, which says that @version tag in each source file should merely hold the current release version of the whole artifact.

From javadoc - The Java API Documentation Generator:

This tag is intended to hold the current version number of the software that this code is part of

But I don't see any usefulness in that at all. Why would anyone have the current release in each source file if you can see it in your build tool (before the artifact is built) or in the name of the artifact (after the artifact is built)?

So can you specify exactly what should be in the @version tag: the version when that file had last changed (so every file in a source artfiact potentially has its own @version tag), or just the version of the artifact (so every source file has the same @version tag)? Is the former approach actually ever used?

1 个答案:

答案 0 :(得分:2)

根据我的经验,版本标记始终包含文件的当前版本。

由于可以在运行时检查注释,因此检查文件上的版本注释可能很有用/实用。一个例子可以是从网络位置更新文件(想想视频游戏更新)。

由于注释对程序/编译器比程序员更直接有用,因此版本标记应始终包含当前版本。

但是,每个开发人员可能会以不同方式使用这些版本标记,这取决于他们。在您提交的案例中,他们发现以非预期的方式使用版本标签可以某种方式帮助他们。

所以是的,您可以将任何您喜欢的内容添加到版本标记中。它是否有用是由您的程序决定的。

至于你的上一个问题,是的。从一个开发人员到另一个开发人员的版本编号差异很大(我在公司/组的上下文中使用术语开发人员,而不是个人)。一些开发人员为每个稳定版本使用单个版本号。其他人使用单独的文件版本号。

我更喜欢后者,因为它可以让您查看某些文件的更新或更改频率。

这当然是猜想和观点。