Gradle-Build:无法将提供的表示法转换为文件或URI

时间:2018-01-25 20:35:48

标签: java gradle intellij-idea build.gradle

使用以下gradle.build文件在IntelliJ中使用Gradle构建时:

version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'idea'

sourceCompatibility = 1.8
repositories {
    mavenCentral()
}

dependencies {

    // https://mvnrepository.com/artifact/org.jdom/jdom
    compile (
            [group: 'org.jdom', name: 'jdom', version: '2.0.0'],
            [group: 'org.controlsfx', name: 'controlsfx', version: '8.40.14'],
            [group: 'net.java.openjfx.backport', name: 'openjfx-78-backport-compat', version: '1.8.0.1']
    )
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

jar {
    manifest {
        from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
        attributes 'Main-Class': 'de.to.main.class.itv.Main'
    }
}

我收到以下错误:

9:44:43 PM: Executing task 'build'...

Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
:compileJava
:processResources
:classes
:jar FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Could not copy MANIFEST.MF to 'C:\Users\pre name\Java\Uni\SWP\ITV\build\tmp\jar\MANIFEST.MF'.
> Cannot convert the provided notation to a File or URI: [ZIP 'D:\Development\.gradle\caches\modules-2\files-2.1\org.jdom\jdom\2.0.0\e03447aa5a53e7ee9f0ebb9da64c5c178900173d\jdom-2.0.0.jar', ZIP 'D:\Development\.gradle\caches\modules-2\files-2.1\org.controlsfx\controlsfx\8.40.14\7338f13794b82c77ea152803df56a15d376c3b0e\controlsfx-8.40.14.jar', ZIP 'D:\Development\.gradle\caches\modules-2\files-2.1\net.java.openjfx.backport\openjfx-78-backport-compat\1.8.0.1\7cb8f4c47f25736b099d0db2a0c518e909ed6e4d\openjfx-78-backport-compat-1.8.0.1.jar'].
  The following types/formats are supported:
    - A String or CharSequence path, for example 'src/main/java' or '/usr/include'.
    - A String or CharSequence URI, for example 'file:/usr/include'.
    - A File instance.
    - A Path instance.
    - A URI or URL instance.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED in 1s
3 actionable tasks: 3 executed
Cannot convert the provided notation to a File or URI: [ZIP 'D:\Development\.gradle\caches\modules-2\files-2.1\org.jdom\jdom\2.0.0\e03447aa5a53e7ee9f0ebb9da64c5c178900173d\jdom-2.0.0.jar', ZIP 'D:\Development\.gradle\caches\modules-2\files-2.1\org.controlsfx\controlsfx\8.40.14\7338f13794b82c77ea152803df56a15d376c3b0e\controlsfx-8.40.14.jar', ZIP 'D:\Development\.gradle\caches\modules-2\files-2.1\net.java.openjfx.backport\openjfx-78-backport-compat\1.8.0.1\7cb8f4c47f25736b099d0db2a0c518e909ed6e4d\openjfx-78-backport-compat-1.8.0.1.jar'].
The following types/formats are supported:
  - A String or CharSequence path, for example 'src/main/java' or '/usr/include'.
  - A String or CharSequence URI, for example 'file:/usr/include'.
  - A File instance.
  - A Path instance.
  - A URI or URL instance.
9:44:44 PM: Task execution finished 'build'.

我猜测路径中会出现whitspace错误,但是在将服务目录路径更改为没有whitspace的路径之后,错误将保持不变。

目标是构建一个包含外部依赖项的项目jar。 问题是,提供的注释有什么问题?

1 个答案:

答案 0 :(得分:5)

我认为你在这里遇到了方法范围问题。

在你的街区:

jar {
  manifest {
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    attributes 'Main-Class': 'de.to.main.class.itv.Main'
  }
}

您首先在jar任务中调用manifest(Action<? super Manifest> configureAction)方法。在该机构内部,您正在Manifest类型上调用from(Object... mergePath)

  

指定要合并到此清单中的其他清单。

from上的方法名称Manifest会影响来自AbstractCopyTaskJar继承自)的各种from方法。

如果要使用工件配置事物包,您应该做的是在任务类型上调用from。只需将from移到manifest之外,您就会看到更明确的信息,或者事情会有效。

jar {
  from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
  manifest {
    attributes 'Main-Class': 'de.to.main.class.itv.Main'
  }
}