前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >mvn 打包带clean和不带clean区别(下)

mvn 打包带clean和不带clean区别(下)

原创
作者头像
陈不成i
修改2021-06-28 18:07:33
1.1K0
修改2021-06-28 18:07:33
举报
文章被收录于专栏:ops技术分享ops技术分享

所以除了那个强制的参数以外,就是看什么时候 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包不是最新的:

  1. jar包不存在(其实就是mvn clean的效果)
  2. 传入比较的文件资源不存在
  3. Resource with unknown modification date found,资源的修改时间未知
  4. Resource with newer modification date found,jar包的最后修改时间比资源的最后修改时间早

总结

  1. 理论上来讲不做mvn clean 得到的jar包应该是最新的,除非其他方式修改jar包中的内容而不修改源代码。
  2. 平时可以用mvn install,而不进行chean节省时间(如果你觉得节省时间多的话),但最保险还是用 mvn clean install 生成最新的jar包或其他包
  3. 不想用mvn clean又想保证jar包最新,建议添加 -Djar.forceCreation 参数

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档