Slow "compiling script into cache" at 1 build.gradle per second

Hi!

I have more than 300 projects in a commercial multi-project build. And the configuration phase of an initial build takes more than 5 minutes! About 1 second per each build.gradle file. It is faster the next time, but it happens a lot that the script cache is empty (on build servers). Why is this compilation so slow? I mean, these are only small build scripts with less than 20 lines. Is there a way to speed up the initial configuration time?

Thanks in advance!

I can’t say without any more details about the environment you are on.

You could try with the [nightly build](http://gradle.org/nightly) as we’ve made some optimisations that affect compilation, that will roll out in 2.4.

Hi!

Then I guess it is not normal for the configuration phase to take this long, so I must have messed up something. It is not easy to provide much more details here, because it is a huge project. We use Gradle 2.2.1 on a Linux machine anyway. And 2.4 nightly does not make any difference.

One clue, it seems that actual configuration resolution has slipped into the configuration phase somehow, and although it usually does not download anything, I can imagine that it can take time to deal with the resolution details, resolving conficting versions, etc. With a clean gradle-user-home, it does download many things actually.

If you aggree that this can slow down the configuration phase, then there is a suspicious part that may cause this, but I do not know how can I do it better, to avoid actual artifact resolution.

We have a workaround for the missing “provided” configuration in the build so we do not use the “compile” configuration directly. It only extends from the [compileBase, provided] configuration. And we want to make sure that nobody puts any dependencies into “compile” configuration directly. So we have a safety check for this:

subprojects.afterEvaluate {
    if (!configurations.compile.dependencies.empty) {
        throw new GradleException("Error: do not use compile directly...")
    }
}

But it actually resolves the artifacts.

Is there any way to check a configuration whether it is empty and also avoid artifact resolution at the same time? I think it would be much help for me. As the configuration already gets faster if I remove this safety check.

Thank you!

If you’re seeing “compiling script into cache” then it’s not a configuration time problem. 1 sec to compile a script is very slow. This could be cause by an underpowered machine or slow file system (e.g. NFS).
As for the dependency resolution aspect, ‘configurations.compile.dependencies.empty’ will not trigger a dependency resolution. It just looks at the list of declared dependencies, so something else is doing it. Here’s a snippet you can inject into the root of the build to find out where it is happening.

’’‘
def afterEvaluation = false
gradle.projectsEvaluated {
    afterEvaluation = true
}

allprojects { project ->
    configurations.all { configuration ->
        configuration.incoming.beforeResolve {
           if (!afterEvaluation) {
               throw new Exception(“Configuration $configuration.name of project $project.name is being resolved at configuration time.”)
           }
        }
    }
}
’’’