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

Nie*_*els 2 java intellij-idea gradle 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'
    }
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

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'.
Run Code Online (Sandbox Code Playgroud)

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

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

mko*_*bit 5

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

在你的块中:

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

您首先manifest(Action<? super Manifest> configureAction)jar任务中调用该方法.在那个身体内部,你正在呼唤from(Object... mergePath)这种Manifest类型.

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

阴影from上的方法名称来自(继承自)Manifest的各种from方法.AbstractCopyTaskJar

如果要使用工件配置事物包,您应该做的是调用from任务类型.只需移动它的from外部,manifest你应该看到一个更清晰的信息或事情将成功.

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