Toumi
Toumi

Reputation: 3155

only build script and other plugins script blocks are allowed before plugins

I want to use gradle plugin having this syntax

 plugins {
  id "id" version "version"
}

but i have the error of

only build script and other plugins script blocks are allowed before plugins 

I moved it to the bloc buildscript but still not working.

How can i apply this kind of plugin ?

This is the plugin that I want to include in my project

gradle git properties plugin

and here is the output of my gradle version

    Gradle 4.3.1
------------------------------------------------------------

Build time:   2017-11-08 08:59:45 UTC
Revision:     e4f4804807ef7c2829da51877861ff06e07e006d

Groovy:       2.4.12

Upvotes: 61

Views: 63962

Answers (4)

TheTechGuy
TheTechGuy

Reputation: 17384

Google firebase documentation is kind of messed up, they are asking to add the following code

plugins {
  id 'com.google.gms.google-services'
}

but it should really be following at the very top of the file (more like include)

apply plugin 'com.google.gms.google-services'

Make sure this is the first line in the file.

Upvotes: 6

Andres R
Andres R

Reputation: 193

I noticed a plugin line before the android block that said apply plugin: 'com.android.application'. Since the firebase configuration ask me for the 'com.google.gms.google-services' plugin I just add:

apply plugin: 'com.google.gms.google-services'

Upvotes: 6

Tesla
Tesla

Reputation: 7

I solved this just by deleting.

task clean(type: Delete) { delete rootProject.buildDir }

Upvotes: -6

Lukas Körfer
Lukas Körfer

Reputation: 14523

Whenever you write a build.gradle script and use the new plugins script block, you need to put it as first block in the file. The only exceptions from this rule are other plugins blocks or the special buildScript block, which always must go first.

As an example, this script is fine:

plugins {
    // ...
}

dependencies {
    // ...
}

This one is also fine:

buildScript {
    // ...
}

plugins {
    // ...
}

repositories {
    // ...
}

But this one is invalid:

repositories {
     // ...
}

plugins {
    // ...
}

Upvotes: 104

Related Questions