4

I'm trying to create a library and publish it to maven local. When I start trying to add a MavenPublication to publications, the IDE gives it a dotted underline like it's an unresolved reference. Same with parameters like from and artifact.

If I uncomment the pom block, gradle sync fails and says Cause: invalid type code: B3, ultimately because of org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException on one of the parameters within.

IntelliJ Idea screen shot

This build.gradle file is in one of my modules. The top level build.gradle is pretty simple.

buildscript {

    repositories {
        mavenLocal()
        mavenCentral()
        maven { url "https://plugins.gradle.org/m2/" }
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        jcenter()
    }
    dependencies {

    }
}

allprojects {
    apply plugin: "idea"

    group = 'com.mygroup'
    version = '1.0.0'

    repositories {
        mavenLocal()
        mavenCentral()
        jcenter()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        maven { url "https://oss.sonatype.org/content/repositories/releases/" }
    }
}

And here's the module's build.gradle.

plugins {
    id 'java-library'
    id 'maven-publish'
    id 'signing'
}

task sourcesJar(type: Jar) {
    from sourceSets.main.allJava
    archiveClassifier = 'sources'
}

task javadocJar(type: Jar) {
    from javadoc
    archiveClassifier = 'javadoc'
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            artifactId = 'mylibrary'
            from components.java
            artifact sourcesJar
            artifact javadocJar
            pom {
                name = 'MyLibrary'
                organization {
                    name 'MyOrg'
                    url 'www.myurl.com'
                }
            }
        }
    }
}

signing {
    sign publishing.publications.mavenJava
}

javadoc {
    if(JavaVersion.current().isJava9Compatible()) {
        options.addBooleanOption('html5', true)
    }
}

I'm using Gradle 5.1.1, IntelliJ Idea 2019.1.2, and JDK 12.0.1.

7
  • Does Gradle build from command line work? Try using latest 5.2 Gradle version. Seems that such DSL is not supported for 5.1 version. Commented May 22, 2019 at 8:50
  • I just tried 5.2.1 and 5.4.1 and they all have the same issues. Commented May 22, 2019 at 12:00
  • Can you please post the module's build.gradle with pom block? Otherwise, I have to add my own, specifically from the official Gradle doc. And it works just fine with your build.gradle scripts. With regards to the dotted underlines, it's a problem with IntelliJ support for Gradle build scripts written in Groovy Commented May 25, 2019 at 9:56
  • 1
    IntelliJ Idea 2019.1.2 and JDK 12.0.1. And in the process of coming up with a minimal pom block to make it fail above, I think I found the issue, because if I add = signs, it completes the sync without errors. Why are equal signs necessary here, but not in a plugins block where you have lines like `id 'maven-publish'? Commented May 25, 2019 at 11:58
  • 1
    @Chriki My follow-up question was about the syntax confusion and Dmitry helped with that, too. Thanks. Commented May 25, 2019 at 19:57

1 Answer 1

1
+500

As it's a bit long explanation, let me clarify the situation here instead of replying in the comments to my question about providing the complete example with a pom-offender block. As the OP has already figured out, the problem is in the missing = sign. It's necessary for pom.organization and must not be present in the plugin.id.

For plugins block, it's a well-known Groovy convention of method call, which allow us to omit parentheses. And you can't use assignment here because id is not a property of a class. Look at the Gradle source code for plugins block.

However, if we look at pom.organization block we see the receiver of Action is MavenPomOrganization which has getName() and getUrl() returning Property<String> and not taking any arguments. From bare Groovy standpoint, it's definitely not the case of omitting parentheses. But I don't know for sure how the assignment syntax (name = 'MyOrg') works here under the hood. At first glance I can just speculate that it's some sort of Gradle magic using Groovy magic, e.g. AST transformation or something

Sign up to request clarification or add additional context in comments.

2 Comments

Are the dotted underlines in Idea a bug in their Groovy parser?
@Tenfour04 IntelliJ has not been "fixing" this kind of problems for many years now. It's sort of a pain point for all Gradle users. The reason behind this is the dynamic nature of Groovy which is powerful but not so easy to support in IDE. As a result of not supporting the Gradle Groovy DSL in IntelliJ, the Gradle team decided to move to Kotlin DSL which is "surprisingly" is a child of JetBrains and it's a statically compiled language with powerful features taken from many existing languages. Of course, we can raise this issue with JB team but I'm sure it won't be fixed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.