仅在清单更改时阻止执行jar任务

时间:2016-05-13 20:15:32

标签: gradle

我正在使用Gradle 2.12。在我的构建文件中,我配置每个模块应该在清单中放置额外的信息。我是这样做的:

tasks.withType(Jar) {
    manifest {
        attributes(
                'Build-By': buildBy,
                'Build-JDK': buildJdk,
                'Build-Time-ISO-8601': buildTime_ISO_8601,
                'Build-SCM-Info': buildScmInfo
        )
    }

变量在构建开始时初始化一次。

这很好用,但有一个缺点:它会导致jar任务始终被调用,因为它发现了它的输入'改变了,所有依赖于jar版的模块都被重新编译,这是不必要的。例如,项目结构:

A,B取决于A,C取决于A

当第二次执行构建而没有任何代码更改时,A不会被编译,但会构建一个新的jar,因此需要重新编译B和C,因为它们的依赖项已更改。

如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

您可以尝试将清单规范移出配置阶段(通过在tasks.withType(Jar) { doFirst { manifest { attributes \ 'Build-By': buildBy, 'Build-JDK': buildJdk, 'Build-Time-ISO-8601': buildTime_ISO_8601, 'Build-SCM-Info': buildScmInfo } } } 闭包中声明),使Gradle在默认清单文件中查找尚未更改的更改。像这样的事情:

USE [msdb]
GO

/****** Object:  Job [IstgSms48.SendSms]    Script Date: 05/16/2016 12:25:12 ب.ظ ******/
BEGIN TRANSACTION
DECLARE @ReturnCode INT
SELECT @ReturnCode = 0
/****** Object:  JobCategory [Database Maintenance]    Script Date: 05/16/2016 12:25:12 ب.ظ ******/
IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'Database Maintenance' AND category_class=1)
BEGIN
EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'Database Maintenance'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback

END

DECLARE @jobId BINARY(16)
EXEC @ReturnCode =  msdb.dbo.sp_add_job @job_name=N'IstgSms48.SendSms', 
        @enabled=0, 
        @notify_level_eventlog=2, 
        @notify_level_email=0, 
        @notify_level_netsend=0, 
        @notify_level_page=0, 
        @delete_level=0, 
        @description=N'No description available.', 
        @category_name=N'Database Maintenance', 
        @owner_login_name=N'IstgBazian', @job_id = @jobId OUTPUT
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object:  Step [SendSms]    Script Date: 05/16/2016 12:25:14 ب.ظ ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'SendSms', 
        @step_id=1, 
        @cmdexec_success_code=0, 
        @on_success_action=1, 
        @on_success_step_id=0, 
        @on_fail_action=2, 
        @on_fail_step_id=0, 
        @retry_attempts=0, 
        @retry_interval=0, 
        @os_run_priority=0, @subsystem=N'SSIS', 
        @command=N'/Server "$(ESCAPE_NONE(SRVR))" /SQL "Maintenance Plans\IstgSms48" /set "\Package\SendSms.Disable;false"', 
        @flags=0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id=@jobId, @name=N'IstgSms48.SendSms', 
        @enabled=1, 
        @freq_type=4, 
        @freq_interval=1, 
        @freq_subday_type=4, 
        @freq_subday_interval=1, 
        @freq_relative_interval=0, 
        @freq_recurrence_factor=0, 
        @active_start_date=20150312, 
        @active_end_date=99991231, 
        @active_start_time=0, 
        @active_end_time=235959, 
        @schedule_uid=N'3e6d4d84-da6c-4e08-a36e-34b105b7ffaf'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
COMMIT TRANSACTION
GOTO EndSave
QuitWithRollback:
    IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION
EndSave:

GO

在这种情况下,只有在执行jar任务时才应更改Manifest内容。