如何使用Jython plugin下载依赖项并使用Gradle将它们添加到类路径中?
存储库任务包括:
maven{url "https://plugins.gradle.org/m2/"}
和依赖项任务有:
compile "gradle.plugin.com.github.rzabini:gradle-jython:1.0.2"
这是否拉入Jython本身?我没有看到它确实如此,因为在删除~/gradle/cache/
gradle后重新下载插件但我没有看到JAR&#39>
thufir@doge:~/NetBeansProjects/nfl$
thufir@doge:~/NetBeansProjects/nfl$ gradle clean run
:clean UP-TO-DATE
:compileJava
Download https://plugins.gradle.org/m2/gradle/plugin/com/github/rzabini/gradle-jython/1.0.2/gradle-jython-1.0.2.pom
Download https://plugins.gradle.org/m2/de/undercouch/gradle-download-task/2.0.0/gradle-download-task-2.0.0.pom
Download https://plugins.gradle.org/m2/gradle/plugin/com/github/rzabini/gradle-jython/1.0.2/gradle-jython-1.0.2.jar
Download https://plugins.gradle.org/m2/de/undercouch/gradle-download-task/2.0.0/gradle-download-task-2.0.0.jar
:processResources UP-TO-DATE
:classes
:runJan 16, 2017 5:25:17 AM net.bounceme.dur.nfl.Run main
INFO: hello nfl
Jan 16, 2017 5:25:17 AM net.bounceme.dur.nfl.Run init
INFO: will now invoke jython
Jan 16, 2017 5:25:17 AM net.bounceme.dur.nfl.JythonBean <init>
INFO: java bean for now..
Jan 16, 2017 5:25:17 AM net.bounceme.dur.nfl.JythonBean createInterpreter
INFO: jython to follow
BUILD SUCCESSFUL
Total time: 6.412 secs
thufir@doge:~/NetBeansProjects/nfl$
但是,添加该行后无法实例化Jython Interpreter:
thufir@doge:~/NetBeansProjects/nfl$
thufir@doge:~/NetBeansProjects/nfl$ gradle run
:compileJava/home/thufir/NetBeansProjects/nfl/src/main/java/net/bounceme/dur/nfl/JythonBean.java:15: error: package org.python.util does not exist
org.python.util.PythonInterpreter interp = new org.python.util.PythonInterpreter();
^
/home/thufir/NetBeansProjects/nfl/src/main/java/net/bounceme/dur/nfl/JythonBean.java:15: error: package org.python.util does not exist
org.python.util.PythonInterpreter interp = new org.python.util.PythonInterpreter();
^
2 errors
FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 2.816 secs
thufir@doge:~/NetBeansProjects/nfl$
thufir@doge:~/NetBeansProjects/nfl$
代码:
package net.bounceme.dur.nfl;
import java.util.logging.Logger;
public class JythonBean {
private static final Logger log = Logger.getLogger(JythonBean.class.getName());
public JythonBean() {
log.info("java bean for now..");
}
public void createInterpreter() {
log.info("jython to follow");
org.python.util.PythonInterpreter interp = new org.python.util.PythonInterpreter();
// interp.execfile("script1.py");
}
}
PythonInterpreter行已针对第一个gradle运行进行了注释,以便它成功。我也从Netbeans尝试了这个,干净和构建,同样的结果。
构建文件:
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'application'
String mavenGroupId = 'thufir'
String mavenVersion = '1.0-SNAPSHOT'
sourceCompatibility = '1.8'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
// NetBeans will automatically add "run" and "debug" tasks relying on the
// "mainClass" property. You may however define the property prior executing
// tasks by passing a "-PmainClass=<QUALIFIED_CLASS_NAME>" argument.
//
// Note however, that you may define your own "run" and "debug" task if you
// prefer. In this case NetBeans will not add these tasks but you may rely on
// your own implementation.
mainClassName = 'net.bounceme.dur.nfl.Run'
if (!hasProperty('mainClass')) {
ext.mainClass = 'net.bounceme.dur.nfl.Run'
}
repositories {
// mavenCentral()
// You may define additional repositories, or even remove "mavenCentral()".
// Read more about repositories here:
// http://www.gradle.org/docs/current/userguide/dependency_management.html#sec:repositories
maven{
url "https://plugins.gradle.org/m2/"}
}
dependencies {
//TODO: Add dependencies here ...
//You can read more about how to add dependency here:
//http://www.gradle.org/docs/current/userguide/dependency_management.html#sec:how_to_declare_your_dependencies
//testCompile group: 'junit', name: 'junit', version: '4.10'
// compile 'com.google.api-client:google-api-client:1.20.0'
// classpath "gradle.plugin.com.github.rzabini:gradle-jython:1.0.2"
compile "gradle.plugin.com.github.rzabini:gradle-jython:1.0.2"
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
// java.srcDirs = ['src']
// resources.srcDirs = ['src']
// aidl.srcDirs = ['src']
// renderscript.srcDirs = ['src']
// res.srcDirs = ['res']
// assets.srcDirs = ['assets']
}