所以除了那个强制的参数以外,就是看什么时候 isUptodate 为true,查看关键代码:
代码语言:javascript复制protected boolean isUptodate()
throws ArchiverException
{
final File zipFile = getDestFile();
final long destTimestamp = zipFile.lastModified();
if ( destTimestamp == 0 )
{
getLogger().debug( "isUp2date: false (Destination " zipFile.getPath() " not found.)" );
return false; // File doesn't yet exist
}
final Iterator it = resources.iterator();
if ( !it.hasNext() )
{
getLogger().debug( "isUp2date: false (No input files.)" );
return false; // No timestamp to compare
}
while ( it.hasNext() )
{
final Object o = it.next();
final long l;
if ( o instanceof ArchiveEntry )
{
l = ( (ArchiveEntry) o ).getResource()
.getLastModified();
}
else if ( o instanceof PlexusIoResourceCollection )
{
try
{
l = ( (PlexusIoResourceCollection) o ).getLastModified();
}
catch ( final IOException e )
{
throw new ArchiverException( e.getMessage(), e );
}
}
else
{
throw new IllegalStateException( "Invalid object type: " o.getClass()
.getName() );
}
if ( l == PlexusIoResource.UNKNOWN_MODIFICATION_DATE )
{
// Don't know what to do. Safe thing is to assume not up2date.
getLogger().debug( "isUp2date: false (Resource with unknown modification date found.)" );
return false;
}
if ( l > destTimestamp )
{
getLogger().debug( "isUp2date: false (Resource with newer modification date found.)" );
return false;
}
}
getLogger().debug( "isUp2date: true" );
return true;
}
代码中提到有这么几个情况,会认为jar包不是最新的:
- jar包不存在(其实就是mvn clean的效果)
- 传入比较的文件资源不存在
- Resource with unknown modification date found,资源的修改时间未知
- Resource with newer modification date found,jar包的最后修改时间比资源的最后修改时间早
总结
- 理论上来讲不做mvn clean 得到的jar包应该是最新的,除非其他方式修改jar包中的内容而不修改源代码。
- 平时可以用mvn install,而不进行chean节省时间(如果你觉得节省时间多的话),但最保险还是用 mvn clean install 生成最新的jar包或其他包
- 不想用mvn clean又想保证jar包最新,建议添加 -Djar.forceCreation 参数