简体   繁体   English

如何在Gradle中添加“系统”依赖?

[英]How do you add a “system” dependency in Gradle?

I have a pom.xml that looks like this: 我有一个看起来像这样的pom.xml

<dependencies>
    <dependency>
        <groupId>javafx-packager</groupId>
        <artifactId>javafx-packager</artifactId>
        <version>1.8.0_40</version>
        <scope>system</scope>
        <systemPath>${java.home}/../lib/ant-javafx.jar</systemPath>
    </dependency>
</dependencies>

How do I do the same in Gradle? 我如何在Gradle中做同样的事情?

Update : I tried doing this: 更新 :我试过这样做:

dependencies {
    compile files("${System.getenv('JAVA_HOME')}/../lib/ant-javafx.jar")
}

as suggested by Giuseppe Ricupero, but I'm still getting the compile errors: 正如Giuseppe Ricupero所建议的,但我仍然遇到编译错误:

>gradle build

> Task :compileJava FAILED
C:\Users\pupeno\Documents\Dashman\code\custom-file-extension-windows-bundler\src\main\java\com\oracle\tools\packager\windows\CustomLauncherFileExtensionAppBundler.java:17: error: cannot find symbol
import static com.oracle.tools.packager.StandardBundlerParam.*;
                                       ^
  symbol:   class StandardBundlerParam
  location: package com.oracle.tools.packager
C:\Users\pupeno\Documents\Dashman\code\custom-file-extension-windows-bundler\src\main\java\com\oracle\tools\packager\windows\CustomLauncherFileExtensionAppBundler.java:18: error: cannot find symbol
import static com.oracle.tools.packager.windows.WindowsBundlerParam.*;
                                               ^
  symbol:   class WindowsBundlerParam
  location: package com.oracle.tools.packager.windows
C:\Users\pupeno\Documents\Dashman\code\custom-file-extension-windows-bundler\src\main\java\com\oracle\tools\packager\windows\CustomLauncherFileExtensionAppBundler.java:23: error: cannot find symbol
public class CustomLauncherFileExtensionAppBundler extends AbstractImageBundler {

The full pom.xml I'm trying to convert to Gradle is: 我正在尝试转换为Gradle的完整pom.xml是:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>de.dynamicfiles.projects.javafx.bundler</groupId>
    <artifactId>custom-file-extension-windows-bundler</artifactId>
    <version>1.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <developers>
        <developer>
            <name>Danny Althoff</name>
            <email>fibrefox@dynamicfiles.de</email>
            <url>https://www.dynamicfiles.de</url>
        </developer>
    </developers>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

        <version.java.source>1.8</version.java.source>
        <version.java.target>1.8</version.java.target>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>${version.java.source}</source>
                    <target>${version.java.target}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.0.1</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                            <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                        </manifest>
                        <manifestEntries>
                            <display_version>${display_version}</display_version>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>javafx-packager</groupId>
            <artifactId>javafx-packager</artifactId>
            <version>1.8.0_40</version>
            <scope>system</scope>
            <systemPath>${java.home}/../lib/ant-javafx.jar</systemPath>
        </dependency>
    </dependencies>
</project>

Update 2 : I tried gradle init like Giuseppe Ricupero recommended and it came up with this build.gradle : 更新2 :我尝试了像Giuseppe Ricupero推荐的gradle init ,它提出了这个build.gradle

apply plugin: 'java'
apply plugin: 'maven'

group = 'de.dynamicfiles.projects.javafx.bundler'
version = '1.0.1-SNAPSHOT'

description = """"""

sourceCompatibility = 1.8
targetCompatibility = 1.8
tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

repositories {
    maven { url "http://repo.maven.apache.org/maven2" }
}

dependencies {
    system group: 'javafx-packager', name: 'javafx-packager', version: '1.8.0_40'
}

but that doesn't work, it throws this error: 但这不起作用,它会抛出这个错误:

> Could not find method system() for arguments [{group=javafx-packager, name=javafx-packager, version=1.8.0_40}] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

UPDATE UPDATE

The gradle init task automatically (try to?) convert(s) the pom.xml into the equivalent gradle files. gradle init任务自动(尝试?)将pom.xml转换为等效的gradle文件。 You can try them: 你可以尝试一下:

build.gradle 的build.gradle

apply plugin: 'java'
apply plugin: 'maven'

group = 'de.dynamicfiles.projects.javafx.bundler'
version = '1.0.1-SNAPSHOT'

description = ""

sourceCompatibility = 1.8
targetCompatibility = 1.8
tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

repositories {
    maven { url "http://repo.maven.apache.org/maven2" }
}

dependencies {
    system group: 'javafx-packager', name: 'javafx-packager', version:'1.8.0_40'
}

settings.gradle settings.gradle

rootProject.name = 'custom-file-extension-windows-bundler'

If you mix this with the original answer: 如果你把它与原来的答案混在一起:

apply plugin: 'java'
apply plugin: 'maven'

group = 'de.dynamicfiles.projects.javafx.bundler'
version = '1.0.1-SNAPSHOT'

description = """"""

sourceCompatibility = 1.8
targetCompatibility = 1.8
tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

repositories {
    maven { url "http://repo.maven.apache.org/maven2" }
}

dependencies {
    compile files("${System.getenv('JAVA_HOME')}/lib/ant-javafx.jar")
}

it works. 有用。


Original answer 原始答案

I think you need just to add a file dep like: 我想你只需要添加一个文件dep:

dependencies {
    compile files("${System.getenv('JAVA_HOME')}/../lib/ant-javafx.jar")
}

You can see more in the docs . 您可以在文档中看到更多内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM