What exactly is "The plugins {} block must not be used here. If you need to apply a plugin imperatively"? - gradle

I have a gradle project that uses kotlin dsl:
plugins {
base
kotlin("jvm") version "1.3.70" apply false
}
//val scalaV: String by project
//val ext = SpikeExt(this)
allprojects {
apply(plugin = "java")
apply(plugin = "scala")
group = "com.tribbloids.scalaspike"
version = "1.0.0-SNAPSHOT"
repositories {
mavenCentral()
jcenter()
maven("https://dl.bintray.com/kotlin/kotlin-dev")
}
dependencies {
}
}
when I run gradlew build I encounter the following error:
FAILURE: Build failed with an exception.
* Where:
Script '/home/peng/git/scalaspike/build.gradle.kts' line: 1
* What went wrong:
The plugins {} block must not be used here. If you need to apply a plugin imperatively, please use apply<PluginType>() or apply(plugin = "id") instead.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 870ms
In the mean time, the exact identical line 1 works normal in the other project:
https://github.com/gradle/kotlin-dsl-samples/tree/master/samples/multi-kotlin-project
plugins {
base
kotlin("jvm") version "1.3.70" apply false
}
allprojects {
group = "org.gradle.kotlin.dsl.samples.multiproject"
version = "1.0"
repositories {
jcenter()
}
}
dependencies {
// Make the root project archives configuration depend on every sub-project
subprojects.forEach {
archives(it)
}
}
So I have 2 questions:
what does this mean?
why the same thing works in the second project but fails on the first project? What is the difference?

Related

Maven publication 'maven' cannot include multiple components

When I am building multi-project with multibranch using this command with Gradle 6.0:
./gradlew :soa-report-consumer-multi_master:soa-report-consumer-api:build publishMavenPublicationToMavenRepository -x test -PpubRepoUrl=https://nexus.balabala.com/repository/maven-releases/ -PmultibranchProjDir=soa-report-consumer-multi_master
shows this eror:
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/dabaidabai/.jenkins/workspace/t-consumer-multi_feature_happygo/build.gradle' line: 35
* What went wrong:
A problem occurred evaluating project ':t-consumer-multi_feature_happygo'.
> Maven publication 'maven' cannot include multiple components
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
this is my build.gradle config in sub project:
project(":$consumerMultibranchProjDir:soa-report-consumer-api") {
jar {
enabled = true
}
bootJar {
enabled = false
}
archivesBaseName = "soa-report-consumer-api"
version = "1.0.0-RELEASE"
jar {
enabled = true
}
dependencies {
api("com.sportswin.soa:soa-misc-biz:1.0.0-RELEASE")
api project(":soa-wallet:soa-wallet-api")
}
publishing {
publications {
maven(MavenPublication) {
groupId 'com.sportswin.soa'
artifactId 'soa-report-consumer-api'
version '1.0.0-RELEASE'
from components.java
artifact sourceJar {
classifier "sources"
}
}
}
}
}
where is the problem? and what should I do to fix it?
from the part config you shared - I think that you have 2 sources jars
remove explicit sources jar in publishing
project(":$consumerMultibranchProjDir:soa-report-consumer-api") {
jar {
enabled = true
}
bootJar {
enabled = false
}
archivesBaseName = "soa-report-consumer-api"
version = "1.0.0-RELEASE"
dependencies {
api("com.sportswin.soa:soa-misc-biz:1.0.0-RELEASE")
api project(":soa-wallet:soa-wallet-api")
}
publishing {
publications {
maven(MavenPublication) {
groupId 'com.sportswin.soa'
artifactId 'soa-report-consumer-api'
version '1.0.0-RELEASE'
from components.java
}
}
}
}

Could not create task ':GluonApplicationApp:debug'

I am trying to run simply the Gluon single scene example. Here is my gradle output:
Configuration on demand is an incubating feature.
> Configure project :GluonApplicationApp
Project :GluonApplicationApp => no module-info.java found
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':GluonApplicationApp'.
> Could not create task ':GluonApplicationApp:debug'.
> Unnecessarily replacing a task that does not exist is not supported. Use create() or register() directly instead. You attempted to replace a task named 'debug', but there is no existing task with that name.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
My build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:1.3.17'
}
}
apply plugin: 'org.javafxports.jfxmobile'
repositories {
jcenter()
maven {
url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
mainClassName = 'com.gluonapplication.GluonApplication'
dependencies {
compile 'com.gluonhq:charm:5.0.2'
}
jfxmobile {
downConfig {
version = '3.8.6'
// Do not edit the line below. Use Gluon Mobile Settings in your project context menu instead
plugins 'display', 'lifecycle', 'statusbar', 'storage'
}
android {
manifest = 'src/android/AndroidManifest.xml'
}
}
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'org.openjfx:javafx-plugin:0.0.9'
}
}
apply plugin: 'org.openjfx.javafxplugin'
The JDK version i'm using is JDK 11, and I have tried various gradle versions. For my IDE I use netbeans.
I have been trying to fix this all day. Please help
I was using the old Gluon IDE plugin
Gluon build 0.1.29-SNAPSHOT fixes the rest of the problems
More details on comments of the question!

No value has been specified for property 'mainClassName' in shadowJar

I am compile flink using gradle(v6.0.1) build tool like this, but show this error:
~ ⌚ 13:53:42
$ bash -c "$(curl https://flink.apache.org/q/gradle-quickstart.sh)" -- 1.10.0 2.11
~/quickstart ⌚ 14:08:22
$ ./gradlew clean shadowJar
> Task :shadowJar FAILED
FAILURE: Build failed with an exception.
* What went wrong:
A problem was found with the configuration of task ':shadowJar' (type 'ShadowJar').
> No value has been specified for property 'mainClassName'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.0.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 1s
4 actionable tasks: 4 executed
this this my gradle build.gradle:
buildscript {
repositories {
jcenter() // this applies only to the Gradle 'Shadow' plugin
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4'
}
}
plugins {
id 'java'
id 'application'
// shadow plugin to produce fat JARs
id 'com.github.johnrengelman.shadow' version '2.0.4'
}
apply plugin: 'application'
// artifact properties
group = 'org.myorg.quickstart'
version = '0.1-SNAPSHOT'
mainClassName = 'org.myorg.quickstart.StreamingJob'
description = """Flink Quickstart Job"""
ext {
javaVersion = '1.8'
flinkVersion = '1.10.0'
scalaBinaryVersion = '2.11'
slf4jVersion = '1.7.7'
log4jVersion = '1.2.17'
}
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
applicationDefaultJvmArgs = ["-Dlog4j.configuration=log4j.properties"]
// declare where to find the dependencies of your project
repositories {
mavenCentral()
}
// NOTE: We cannot use "compileOnly" or "shadow" configurations since then we could not run code
// in the IDE or with "gradle run". We also cannot exclude transitive dependencies from the
// shadowJar yet (see https://github.com/johnrengelman/shadow/issues/159).
// -> Explicitly define the // libraries we want to be included in the "flinkShadowJar" configuration!
configurations {
flinkShadowJar // dependencies which go into the shadowJar
// always exclude these (also from transitive dependencies) since they are provided by Flink
flinkShadowJar.exclude group: 'org.apache.flink', module: 'force-shading'
flinkShadowJar.exclude group: 'com.google.code.findbugs', module: 'jsr305'
flinkShadowJar.exclude group: 'org.slf4j'
flinkShadowJar.exclude group: 'log4j'
}
// declare the dependencies for your production and test code
dependencies {
// --------------------------------------------------------------
// Compile-time dependencies that should NOT be part of the
// shadow jar and are provided in the lib folder of Flink
// --------------------------------------------------------------
compile "org.apache.flink:flink-java:${flinkVersion}"
compile "org.apache.flink:flink-streaming-java_${scalaBinaryVersion}:${flinkVersion}"
// --------------------------------------------------------------
// Dependencies that should be part of the shadow jar, e.g.
// connectors. These must be in the flinkShadowJar configuration!
// --------------------------------------------------------------
//flinkShadowJar "org.apache.flink:flink-connector-kafka-0.11_${scalaBinaryVersion}:${flinkVersion}"
compile "log4j:log4j:${log4jVersion}"
compile "org.slf4j:slf4j-log4j12:${slf4jVersion}"
// Add test dependencies here.
// testCompile "junit:junit:4.12"
}
// make compileOnly dependencies available for tests:
sourceSets {
main.compileClasspath += configurations.flinkShadowJar
main.runtimeClasspath += configurations.flinkShadowJar
test.compileClasspath += configurations.flinkShadowJar
test.runtimeClasspath += configurations.flinkShadowJar
javadoc.classpath += configurations.flinkShadowJar
}
run.classpath = sourceSets.main.runtimeClasspath
jar {
manifest {
attributes 'Built-By': System.getProperty('user.name'),
'Build-Jdk': System.getProperty('java.version')
}
}
shadowJar {
configurations = [project.configurations.flinkShadowJar]
}
I am read the some answer to tell that the script do dot have mainClassName,but my config contains the mainClassName config,what should I do to fix this error? I am using macOS catalina.
downgrade the gradle to 4.0.1,it works.this is the gradle-wrapper.properties config:
#Mon Jan 06 13:52:34 CST 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0.1-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
this is the build command:
~/quickstart ⌚ 14:48:25
$ ./gradlew clean shadowJar
Downloading https://services.gradle.org/distributions/gradle-4.0.1-all.zip
........10%.........20%........30%.........40%........50%.........60%.........70%........80%.........90%........100%
Starting a Gradle Daemon (subsequent builds will be faster)
BUILD SUCCESSFUL in 1m 46s
4 actionable tasks: 4 executed
maybe help you.

How can I disable cache-redirector of `org.jetbrains.intellij` for some dependencies?

I want to introduce com.alibaba:fastjson:1.2.58 in my plugin project, but when gradle resolve dependencies, the org.jetbrains.intellij plugin redirect the download request to https://cache-redirector.jetbrains.com/www.jetbrains.com/intellij-repository/releases/com/alibaba/fastjson/1.2.58/fastjson-1.2.58.pom, which is not exists.
How can I force gradle download this dependency from mavenCentral ?
Here is my build.gradle:
buildscript {
repositories {
mavenCentral()
maven {
url "https://oss.sonatype.org/content/repositories/snapshots/"
}
maven {
url 'https://dl.bintray.com/jetbrains/intellij-plugin-service'
}
}
}
plugins {
id "org.jetbrains.intellij" version "0.4.4"
}
dependencies {
implementation 'com.alibaba:fastjson:1.2.58'
}
apply plugin: 'idea'
apply plugin: 'org.jetbrains.intellij'
apply plugin: 'java'
sourceCompatibility = 1.8
targetCompatibility = 1.8
intellij {
version ideaVersion
updateSinceUntilBuild false
plugins = [
"com.jetbrains.php:${phpPluginVersion}",
"com.jetbrains.php.blade:${bladePluginVersion}",
'CSS',
'java-i18n',
'properties',
'git4idea'
]
pluginName 'tw tools'
}
patchPluginXml {
sinceBuild '173'
}
group 'com.baiguiren'
version '1.2'
wrapper {
gradleVersion '5.4.1'
}
Output of ./gradlew clean && ./gradlew build:
BUILD SUCCESSFUL in 0s
1 actionable task: 1 up-to-date
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':prepareSandbox'.
> Could not resolve all files for configuration ':runtimeClasspath'.
> Could not find com.alibaba:fastjson:1.2.58.
Searched in the following locations:
https://cache-redirector.jetbrains.com/www.jetbrains.com/intellij-repository/releases/com/alibaba/fastjson/1.2.58/fastjson-1.2.58.pom
https://cache-redirector.jetbrains.com/www.jetbrains.com/intellij-repository/releases/com/alibaba/fastjson/1.2.58/fastjson-1.2.58.jar
file:/Users/ruby/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/ideaIU/2018.3.5/3abea719ce307bc4f573cba4e3d86f4e35cab07/ideaIU-2018.3.5/com.alibaba/fastjson/1.2.58/ivy-1.2.58.xml
file:/Users/ruby/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/ideaIU/2018.3.5/3abea719ce307bc4f573cba4e3d86f4e35cab07/ideaIU-2018.3.5/fastjson-1.2.58-withKotlin-withSources.xml
file:/Users/ruby/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/ideaIU/2018.3.5/3abea719ce307bc4f573cba4e3d86f4e35cab07/ideaIU-2018.3.5/com.alibaba/fastjson/1.2.58/fastjson-1.2.58.jar
file:/Users/ruby/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/ideaIU/2018.3.5/3abea719ce307bc4f573cba4e3d86f4e35cab07/ideaIU-2018.3.5/fastjson.jar
file:/Users/ruby/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/ideaIC/2018.3.5/78cbcd517ec112fbb0c7b45b00b464c1aa6371f3/fastjson-1.2.58-[classifier].jar
https://cache-redirector.jetbrains.com/plugins.jetbrains.com/maven/com/alibaba/fastjson/1.2.58/fastjson-1.2.58.pom
https://cache-redirector.jetbrains.com/plugins.jetbrains.com/maven/com/alibaba/fastjson/1.2.58/fastjson-1.2.58.jar
file:/Users/ruby/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/com.alibaba/fastjson-1.2.58.xml
file:/Users/ruby/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/ideaIU/2018.3.5/3abea719ce307bc4f573cba4e3d86f4e35cab07/ideaIU-2018.3.5/plugins/fastjson/fastjson.jar
file:/Users/ruby/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/fastjson-1.2.58/fastjson.jar
file:/Users/ruby/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/ideaIC/2018.3.5/78cbcd517ec112fbb0c7b45b00b464c1aa6371f3/fastjson-2018.3.5.jar
Required by:
project :
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
I have tried to Invalid caches and restart, but not work.
I even tried to remove org.jetbrains.intellij plugin, but it's required by the project.
There is nothing wrong with cache-redirector, it's just one of the repositories registered in the project, Gradle checks them all.
Try to add the mavenCentral repo to your build.gradle (at the moment it's defined for buildscript only):
repositories {
mavenCentral()
}

custom gradle plugin causes: Cannot configure the 'publishing' extension

I have a custom gradle plugin in which custom task types and gradle configurations are added. When I apply this plugin before maven-publish it works perfectly fine. But when I add it after apply plugin: 'maven-publish', it fails with error message :
FAILURE: Build failed with an exception.
* Where:
Build file '/scratch/skgupta/git_storage/emdi/integtest/build.gradle' line: 38
* What went wrong:
A problem occurred evaluating root project 'integtest'.
> Cannot configure the 'publishing' extension after it has been accessed.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 7.6 secs
Here is the build.gradle file.
buildscript {
repositories {
maven {
url = "${artifactory_contextUrl}/repo"
}
}
dependencies {
classpath group: 'com.mycomp.proj', name: 'MyCustomPlugin', version: "${pluginVersion}", transitive: true
}
}
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'MyCustomPlugin' // WHen this line is moved above maven-publish, build works fine.
// add jar name and version
jar.archiveName='lrgemaas_small_deploy_3n.jar'
group = 'com.mycom.proj.test'
version = '1.0.3'
dependencies {
compile group: 'eaas.platform', name: 'registry-lookup-client', version: '0.1'
compile group: 'eaas.platform', name: 'registry-client', version: '0.1'
compile configurations.lrgConfig // This configuration is added by MyCustomPlugin
compile configurations.webdriver // This configuration is added by MyCustomPlugin
}
repositories {
maven {
url = "${artifactory_contextUrl}/repo"
}
}
publishing {
publications {
myPublicationName(MavenPublication) {
artifactId 'lrgemaas_small_deploy_3n'
artifact jar.archivePath
}
}
repositories {
maven {
url = "${artifactory_contextUrl}/${artifactory_repoName}"
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
}
}
// workflow for build
defaultTasks 'clean','build','publish'
PS: I tried doing nothing in the custom plugin (i.e., simply return from apply method), but it still gives same error.
Simply replacing:
publishing {
publications {
...
}
}
with following:
publishing.publications {
...
}
worked for me!
Gradle is brittle regarding the order of the plugins. There is a discussion about this exact issue at
https://discuss.gradle.org/t/apply-maven-publish-plugin-from-init-script/2460
"Cool, so this is what happens.
DefaultPublishingExtension which is backing the 'publishing {}' block is a DeferredConfigurable. It's a mechanism that allows to register a configuration block to be executed when an extension is accessed. Unfortunately sometimes it causes unexpected behaviour if you access this kind of extension unawares. This is exactly the case when for example you try to get all the properties of a project (as the release plugin does here: https://github.com/townsfolk/gradle-release/blob/master/src/main/groovy/release/PluginHelper.groovy#L230"
FYI, I use a dynamic version and found that I had to define version prior to apply of my plugins. Probably because java or maven-publish sets the publication details upon application.
I upgraded gradle version from 2.1 to 2.12 and it solved this problem, fwiw.

Resources