Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

build.gradle - Gradle file buildscript block

I′m trying to build my project using gradle. I have de build.gradle file as following:

plugins {
    id "fr.putnami.gwt" version "0.4.0"
    id "info.solidsoft.pitest" version "1.3.0"
    }

buildscript {

  repositories {
        mavenCentral() 
        maven {
            url 'https://plugins.gradle.org/m2/'
        }
  }
  dependencies {
  
    testCompile 'junit:junit:4.12'
    testCompile 'org.easymock:easymock:2.5.2'
    testCompile 'com.google.gwt:gwt-dev:2.8.1'
    compile 'net.sourceforge.plantuml:plantuml:8001'
    classpath 'gradle.plugin.de.fntsoftware.gradle:markdown-to-pdf:1.1.0'
  }
  

}
    
    apply plugin: 'war'
    apply plugin: 'java'
    apply plugin: 'eclipse'
    apply plugin: 'jacoco'
    apply plugin: 'de.fntsoftware.gradle.markdown-to-pdf'

When I try to execute the build task, I always get:

all buildscript {} blocks must appear before any plugins {} blocks in the script

I′ve already tried to put the first block of plugins inside of the buildscript one, but nothing is working. Can someone help me, please?

Thanks


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

1 Reply

0 votes
by (71.8m points)

The error message:

all buildscript {} blocks must appear before any plugins {} blocks in the script

Explains what you need to do: move the buildscript block before the plugins block. E.g.

buildscript {
  repositories { ... }
  dependencies { ... }
  ...
}

plugins {
  ...
}

Don't put one inside the other.

However, regardless of the order, I don't think you are using the two blocks correctly in the first place.

Firstly, the buildscript block is for configuring dependencies used in the actual script, and not what is used for building your project. So things like junit or easymock does not make sense here. You most likely wanted to put the dependencies block outside as these are for the project.

Secondly, the plugins block can be seen as a newer easier way of writing apply plugin where you usually don't have to configure the buildscript classpath. You should use it wherever you can instead of the older and more verbose way. If you are in doubt about how to write a third-party plugin in the newer way, find it in the Gradle Plugins Portal and read the description there.

Try with something like this instead:

plugins {
  id 'java'
  id 'war'
  id 'jacoco'
  id 'eclipse'
  id "fr.putnami.gwt" version "0.4.0"
  id "info.solidsoft.pitest" version "1.3.0"
  id "de.fntsoftware.gradle.markdown-to-pdf" version "1.1.0"
}

repositories {
  mavenCentral() 
}
 
dependencies {
  testCompile 'junit:junit:4.12'
  testCompile 'org.easymock:easymock:2.5.2'
  testCompile 'com.google.gwt:gwt-dev:2.8.1'
  compile 'net.sourceforge.plantuml:plantuml:8001'
}

Also be aware that the Putnami GWT plugin is no longer maintained, but has an (at this time relative) active fork.

Also also, compile is deprecated and you should use implementation if your version of Gradle and your plugins support it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...