Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle Incremental Builds - possible to ignore manifest in up-to-date check?

The subject pretty much asks the question, but for more detail, I have the following in my build.gradle:

jar {
    manifest {
        attributes("Built-By": "Gradle")
        attributes("Build-Version": version)
        attributes("Main-Class": "somePackage.SomeClass")
    }
}

When building, since the manifest is auto-generated, it always thinks the jar task is out of date, even if nothing has changed in the code.

Ideally, I'd like to be able to check to see if the version is the same as the last build. If it is, and if previous task dependencies (compileJava et al) are all UP-TO-DATE, I'd like the jar task to report UP-TO-DATE as well.

Failing that, I'd be pretty happy if I could just get the jar task to ignore the manifest file altogether.

For an individual jar task this isn't such a big deal, but as soon as one jar reports that it's not UP-TO-DATE, all the tasks that depend on it then have to re-compile, re-jar, etc etc, which makes builds take way longer than they actually need to. And since the very first jar task in my dependency path reports that it's not up-to-date because of the manifest issue, that means the whole thing is forced to recompile/re-jar/re-war/re-ear/etc every-single-time, and we're talking about a few hundred thousand lines of code here.

Anyway, if anybody knows of a way to solve this little annoyance I'd be grateful

EDIT

I also have a zip task that depends on the jar task:

task zip(type:Zip, dependsOn:jar) {
    from jar
    include jar.archiveName
    from '.'
    include 'run.bat'
}

Running this command:

gradlew :myProject:zip -Pversion=1.0

I consistently get the following output every time, even if I run it twice in a row with no changes anywhere:

:myProject:compileJava UP-TO-DATE
:myProject:processResources UP-TO-DATE
:myProject:classes UP-TO-DATE
:myProject:jar
:myProject:zip
like image 441
StormeHawke Avatar asked Jan 09 '14 21:01

StormeHawke


People also ask

What is incremental build in Gradle?

Task inputs, outputs, and dependencies Gradle uses this information to determine if a task is up-to-date and needs to perform any work. If none of the inputs or outputs have changed, Gradle can skip that task. Altogether, we call this behavior Gradle's incremental build support.

How do I skip a task in Gradle?

To skip any task from the Gradle build, we can use the -x or –exclude-task option. In this case, we'll use “-x test” to skip tests from the build. As a result, the test sources aren't compiled, and therefore, aren't executed.

Why does Gradle build take so long?

Check your Internet connection. If internet speed is very slow gradle build will also take long time to build. I check by change my wifi internet connection with another one good speed connection. Now build time is normal.


1 Answers

Given above declaration, and assuming that code hasn't changed, the jar task should only be out-of-date if version has changed. (Running with --info will tell you which file(s) have changed.) Best solution is to prevent that, at least at development time. (E.g. don't set version to new Date().)

Also note that out-of-date does not cascade. Downstream tasks will only rerun if their inputs or outputs have changed. They don't care if upstream tasks were up-to-date or not.

like image 73
Peter Niederwieser Avatar answered Oct 15 '22 06:10

Peter Niederwieser