Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

gradle - 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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 {
    // ...
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...