I have this error while trying to compile the flamingo graphic tools for java, using intelliJ.

here is the build.gradle file for the error's project :

import javax.swing.SwingUtilities

dependencies {
  compile project(":trident")
  compile group: 'org.tmatesoft.svnkit', name: 'svnkit', version:'1.2.3.5521'
  compile group:'org.apache.xmlgraphics', name:'batik-swing', version:'1.7'
  compile (group:'org.apache.xmlgraphics', name:'batik-transcoder', version:'1.7') {
    exclude group:'xml-apis'
    exclude group:'xalan'
    exclude group:'commons-io'
    exclude group:'commons-logging'
    exclude group:'org.apache.avalon.framework'
  }
  testCompile group: 'com.jgoodies', name: 'forms', version: '1.2.0'
  testCompile group: 'junit', name: 'junit', version: '4.3.1'
  testCompile group: 'org.easytesting', name: 'fest-assert', version: '1.2'
  testCompile group: 'org.easytesting', name: 'fest-reflect', version: '1.2'
  testCompile group: 'org.easytesting', name: 'fest-swing', version: '1.2.1'
  testCompile group: 'org.easytesting', name: 'fest-swing-junit', version: '1.2.1'
  testCompile group: 'org.easytesting', name: 'fest-swing-junit-4.3.1', version: '1.2.1'
}

sourceSets {
  main
  test
}

test {
  // if we are headless, don't run our tests
  enabled = !Boolean.getBoolean("java.awt.headless")
}

jar {
  manifest {
    attributes(
        "Flamingo-Version": version,
        "Flamingo-VersionName": versionKey,
    )
  }
}

task testJar(type: Jar) {
  classifier = 'tst'

  from sourceSets.test.classes

  manifest {
    attributes(
        "Flamingo-Version": version,
        "Flamingo-VersionName": versionKey,
    )
  }
}

uploadArchives {
  try {
    def x = [deployUsername, deployPassword]
  } catch (Exception e) {
    deployUsername = 'unset'
    deployPassword = ''
  }
  repositories {
    mavenDeployer {
      snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
        authentication userName: deployUsername, password: deployPassword
      }
      repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
        authentication userName: deployUsername, password: deployPassword
      }
      configurePOM(pom)
    }
  }
}

install {
  configurePOM(repositories.mavenInstaller.pom)
}

private def configurePOM(def pom) {
  configureBasePom(pom)
  pom.project {
    name "flamingo"
    description "A fork of @kirilcool's flamingo project"
    url "http://insubstantial.github.com/peacock"
  }
  // deal with a gradle bug where transitive=false is not passed into the generated POM
  pom.whenConfigured {cpom ->
    cpom.dependencies.each {it
      switch (it.artifactId) {
        case 'trident':
          it.classifier = 'swing'
          break
      }
    }
  }
}

I don't know what to add for the version key, nor where.

The project is on GitHub : it's a fork of the original project flamingo.

Here is the build.gradle file inside the root directory:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'de.huxhorn.gradle:de.huxhorn.gradle.pgp-plugin:0.0.3'
    }
}

subprojects {
  apply plugin: 'java'
  apply plugin: 'maven'
  try {
    def test = pgpSecretKeyRingFile // exception will throw if not set
    apply plugin: 'sign'
    apply plugin: de.huxhorn.gradle.pgp.PgpPlugin
  } catch (Exception ignore) {}

  group = 'com.github.insubstantial'
  version = '6.3-SNAPSHOT'
  versionKey = "6.3-defender"
  release = "internal"

  sourceCompatibility = 1.6
  targetCompatibility = 1.6

  configurations {
    maven { extendsFrom archives }
  }

  repositories {
    mavenRepo urls: 'https://oss.sonatype.org/content/groups/staging'
    mavenCentral()
    mavenRepo urls: new File(System.getProperty('user.home'), '.m2/repository').toURI().toString()
  }

  task sourceJar(type: Jar) {
    from sourceSets.main.java
    from sourceSets.main.resources
    classifier = 'sources'
  }

  task javadocJar(type: Jar) {
    dependsOn javadoc
    from javadoc.destinationDir
    classifier = 'javadoc'
  }

  artifacts {
    maven sourceJar
    maven javadocJar
  }

  uploadArchives {
    try {
      def x = [deployUsername, deployPassword]
    } catch (Exception e) {
      deployUsername = 'unset'
      deployPassword = ''
    }
    configuration = configurations.maven
    repositories {
      mavenDeployer {
        snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
          authentication userName: deployUsername, password: deployPassword
        }
        repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
          authentication userName: deployUsername, password: deployPassword
        }
      }
    }
  }

  install {
    configuration = configurations.maven
  }

  configureBasePom = { pom ->
    pom.project {
      modelVersion '4.0.0'
      packaging 'jar'
      scm {
        connection 'scm:git:[email protected]:Insubstantial/insubstantial.git'
        developerConnection 'scm:git:[email protected]:Insubstantial/insubstantial.git'
        url 'scm:git:[email protected]:Insubstantial/insubstantial.git'
      }
      developers {
        developer {
          name 'Kirill Grouchnikov'
          email '[email protected]'
          roles {
            role 'author'
            role 'developer'
          }
        }
        developer {
          name 'Danno Ferrin'
          email '[email protected]'
          roles {
            role 'maintainer'
          }
        }
      }
    }
  }
}

task wrapper(type: Wrapper) {
  gradleVersion = '1.0-milestone-2'
}

moreover, the main build.gradle contains the word "Exception" which raise an error from intelliJ.

1

There are 1 best solutions below

0
On

Well, your main problem is that - and both of these are valid statements, you can select for yourself which you find more appealing - the project is designed for a too old Gradle version for usage with a current Gradle integration and / or your IntelliJ version (or rather its Gradle integration) is too new for usage with that project.

To be more technically precise, the IDE Gradle plugins use the Gradle Tooling API to interact with the Gradle build (run it, get information about source paths, dependencies, tasks, ...). The current version of the Tooling API that is used in the IDE plugins is compatible with builds down to Gradle 1.2 which is really quite ancient already. Your build though is designed for being run with Gradle 1.0-milestone-2 - which is not even a productive release - and defines this in its Gradle wrapper settings.

This means, that if you run Gradle from the commandline, 1.0-milestone-2 is used automatically and the build is working as designed (that's the cool magic of the wrapper). If you try to import the project with the Gradle integration of IntelliJ and tell it to use the projects default wrapper (the default choice and always the best idea and if a project does not use the wrapper, tell them to add it), IntelliJ tells you The project is using an unsupported version of Gradle. Please point to a supported Gradle version in the project's Gradle settings or in the project's Gradle wrapper (if applicable.). I guess you then discarded the message dialog and told IntelliJ to use some local Gradle installation instead and then you get the error you mentioned. (Btw. you should have mentioned that you followed this way, makes helping much easier)

When there are major version bumps in Gradle version, they remove stuff they deprecated long enough before according to their deprecation and removal policy and builds might break with these changes which is exactly what you are exhibiting, as you use a Gradle version that this build is not designed for and is not compatible with.

So what you can do is two things.

Either you do not use the Gradle integration in IntelliJ with this project but use Gradle only from the commandline. You can add allprojects { apply plugin: 'idea' } to your build.gradle and then use ./gradlew idea to generate properly configured IntelliJ project files that you then can open with IntelliJ and work with the project.

The other option - and I would really recommend it, even if it is more work - is to update the build to be compatible with current Gradle versions and configure the wrapper to use that new version, then the integration works flawlessly and you also benefit from all development that was done in Gradle since that really old version. You can read the release notes for important changes and breaking changes and interesting changes. To just get it done it should also be sufficient to update to the latest 1.x version, fix all deprecated warnings, update to the latest 2.x version, fix all deprecated warnings, update to the latest 3.x version, fix all deprecated warnings and then update to the latest 4.x version. This should at least make the build working with the latest version in a guided way, even though the build might not be the best one, not using some of the new things that were added to Gradle in the meantime. But this could at least be used as a starter.

You might be tempted to think you can also do a middle-thing and just set the wrapper to use 1.2. As it is in the same major version, the build should work with it and as I said before, 1.2 is currently the oldest version that is working with the integration. At least partly. Things like cancelling a build will e. g. not work as 1.2 does not yet support this, even if the tooling API does. But this won't work, because the build as it is does not even with 1.0. As 1.0-milestone-2 was only a pre-release, there the stability guarantees of course did not hold yet and there was a change between that and 1.0 that breaks your build.

Regarding the actual two errors you got, the first, the one with the unknown property is exactly one of the breaking changes I mentioned. Previously you could simply set any new property by doing foo = 'value'. The problem is, that people often mistyped properties, e. g. wrote fop = 'value' instead and then wondered why it doesn't work, not getting any helpful error message. So dynamically defined properties were forbidden and you have to do it in the ext namespace like ext { foo = 'value' } or ext.foo = 'value', but only on the first occurrence. This defines the new custom property and later on you can get and set it only by its name. If it shouldn't have been a property of the object in question (the project in your case) in the first place, but just a local variable in the build script, it should simply be defined as local variable like def foo = 'value' like always in Groovy which Gradle is based on.

Regarding the second error, the Exceptions IntelliJ is complaining about. Mine does not complain at all, I don't know what inspections you maybe have enabled or whatever, but if it is ok for Gradle it should be ok for IntelliJ if it is not, you should report it as bug to JetBrains, but as I said, here it is not red. But using exceptions for flow control like in that build script is very bad practice anyway, not only in build scripts, but in Java or even in programming at all.

try {
  def test = pgpSecretKeyRingFile // exception will throw if not set
  apply plugin: 'sign'
  apply plugin: de.huxhorn.gradle.pgp.PgpPlugin
} catch (Exception ignore) {}

could e. g. be written like

if (project.hasProperty('pgpSecretKeyRingFile')) {
  apply plugin: 'sign'
  apply plugin: de.huxhorn.gradle.pgp.PgpPlugin
}

and

try {
  def x = [deployUsername, deployPassword]
} catch (Exception e) {
  deployUsername = 'unset'
  deployPassword = ''
}

could e. g. be written like

if (!(project.hasProperty('deployUsername') && project.hasProperty('deployPassword'))) {
  deployUsername = 'unset'
  deployPassword = ''
}

without changing the meaning of the code