groovy.lang.MissingPropertyException:无法设置未知属性' versionKey'对于项目':火烈鸟'类型为org.gradle.api.Project

时间:2017-12-13 19:43:21

标签: java swing gradle radiance-flamingo

尝试使用intelliJ编译java的flamingo图形工具时出现此错误。

这是错误项目的build.gradle文件:

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
      }
    }
  }
}

我不知道要为版本密钥添加什么,也不知道在哪里添加。

该项目在GitHub上:it's a fork of the original project flamingo

以下是根目录中的build.gradle文件:

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:git@github.com:Insubstantial/insubstantial.git'
        developerConnection 'scm:git:git@github.com:Insubstantial/insubstantial.git'
        url 'scm:git:git@github.com:Insubstantial/insubstantial.git'
      }
      developers {
        developer {
          name 'Kirill Grouchnikov'
          email 'kirillcool@yahoo.com'
          roles {
            role 'author'
            role 'developer'
          }
        }
        developer {
          name 'Danno Ferrin'
          email 'danno.ferrin@shemnon.com'
          roles {
            role 'maintainer'
          }
        }
      }
    }
  }
}

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

此外,main build.gradle包含单词" Exception"这会从intelliJ引发错误。

1 个答案:

答案 0 :(得分:3)

嗯,你的主要问题是 - 这两个都是有效的陈述,你可以自己选择你觉得更有吸引力的东西 - 该项目是为太旧的Gradle版本而设计的,用于当前的Gradle集成和/或您的IntelliJ版本(或者更确切地说,它的Gradle集成)对于该项目的使用来说太新了。

为了在技术上更精确,IDE Gradle插件使用Gradle Tooling API与Gradle构建进行交互(运行它,获取有关源路径,依赖项,任务等的信息)。 IDE插件中使用的当前版本的Tooling API与Gradle 1.2的构建兼容,这已经非常古老了。您的构建版本设计用于使用Gradle 1.0-milestone-2运行 - 这甚至不是高效版本 - 并在其Gradle包装器设置中定义它。

这意味着,如果从命令行运行Gradle,则会自动使用1.0-milestone-2,并且构建工作正常(这是包装器的神奇之处)。如果您尝试使用IntelliJ的Gradle集成导入项目并告诉它使用项目默认包装器(默认选择并始终是最好的想法,如果项目不使用包装器,请告诉他们添加它),IntelliJ告诉你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.)。我猜你然后丢弃了消息对话框并告诉IntelliJ使用一些本地Gradle安装,然后你得到你提到的错误。 (顺便说一句。你应该提到你按照这种方式,让帮助更容易)

当Gradle版本中存在主要版本颠簸时,根据他们的弃用和删除策略,他们会删除他们弃用的内容,并且构建可能会破坏这些更改,这正是您所展示的,因为您使用Gradle版本此版本不是为此而设计的,与之不兼容。

所以你能做的就是两件事。

要么在此项目中不使用IntelliJ中的Gradle集成,而是仅使用命令行中的Gradle。您可以将allprojects { apply plugin: 'idea' }添加到build.gradle,然后使用./gradlew idea生成正确配置的IntelliJ项目文件,然后可以使用IntelliJ打开这些文件并使用该项目。

另一个选项 - 我真的推荐它,即使它是更多的工作 - 是更新构建以与当前的Gradle版本兼容并配置包装器以使用该新版本,然后集成完美地工作,你也可以从Gradle中完成的所有开发中受益,因为这个版本很旧。您可以阅读发行说明,了解重要更改以及重大更改和有趣更改。要完成它,它也应该足以更新到最新的1.x版本,修复所有已弃用的警告,更新到最新的2.x版本,修复所有已弃用的警告,更新到最新的3.x版本,修复所有弃用警告,然后更新到最新的4.x版本。这应该至少使构建以引导的方式使用最新版本,即使构建可能不是最好的构建,也不使用在此期间添加到Gradle的一些新东西。但这至少可以作为首发。

你可能会想到你也可以做一件中间事情,并设置包装器使用1.2。因为它在同一个主要版本中,构建应该与它一起使用,正如我之前所说,1.2是目前使用集成的最老版本。至少部分。取消构建的事情将是e。 G。不起作用,因为1.2即使工具API也不支持。但这不会起作用,因为它的构建甚至不是1.0。由于1.0-milestone-2只是一个预发布版本,当然稳定性保证还没有完成,并且在1.0和1.0之间发生了变化,打破了你的构建。

关于你得到的实际两个错误,第一个,具有未知属性的错误正是我提到的一个重大变化。以前,您可以通过执行foo = 'value'来设置任何新属性。问题是,人们经常输入错误的属性,例如: G。写了fop = 'value',然后想知道为什么它不起作用,没有得到任何有用的错误信息。因此禁止动态定义的属性,您必须在ext命名空间中执行此操作,如ext { foo = 'value' }ext.foo = 'value',但仅限于第一次出现。这定义了新的自定义属性,稍后您只能通过其名称来获取和设置它。如果它首先不应该是有问题的对象(在你的情况下是项目)的属性,而只是构建脚本中的局部变量,那么它应该被简单地定义为局部变量,如{{1就像Gradle基于Groovy一样。

关于第二个错误,def foo = 'value'的IntelliJ正在抱怨。我根本不会抱怨,我不知道你可能启用了哪些检查或者其他什么,但是如果Gradle可以,那么对于IntelliJ应该没问题,如果不是,你应该把它作为bug报告给JetBrains,但正如我所说,这里不是红色。但是,无论如何,在构建脚本中使用流控制的异常都是非常糟糕的做法,不仅在构建脚本中,而且在Java中甚至在编程中都是如此。

Exception

可以。 G。写得像

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

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

可以。 G。写得像

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

不改变代码的含义