添加 maven 存储库以期望与 Gradle 的依赖关系



我已经尝试了一些implementation语法的变体,我认为这些变体在下面是不正确的。 我也不太确定我是否有此依赖项的正确存储库。

运行 Gradle:

thufir@dur:~/NetBeansProjects/expect$ 
thufir@dur:~/NetBeansProjects/expect$ rm -rf $HOME/.gradle/caches/
thufir@dur:~/NetBeansProjects/expect$ 
thufir@dur:~/NetBeansProjects/expect$ gradle clean
BUILD SUCCESSFUL in 769ms
1 actionable task: 1 up-to-date
thufir@dur:~/NetBeansProjects/expect$ 
thufir@dur:~/NetBeansProjects/expect$ gradle clean build
> Task :compileJava
/home/thufir/NetBeansProjects/expect/src/main/java/expect/App.java:4: error: package net.sf.expectit.matcher does not exist
import static net.sf.expectit.matcher.Matchers.contains;
^
/home/thufir/NetBeansProjects/expect/src/main/java/expect/App.java:4: error: static import only from classes and interfaces
import static net.sf.expectit.matcher.Matchers.contains;
^
/home/thufir/NetBeansProjects/expect/src/main/java/expect/App.java:5: error: package net.sf.expectit.matcher does not exist
import static net.sf.expectit.matcher.Matchers.eof;
^
/home/thufir/NetBeansProjects/expect/src/main/java/expect/App.java:5: error: static import only from classes and interfaces
import static net.sf.expectit.matcher.Matchers.eof;
^
/home/thufir/NetBeansProjects/expect/src/main/java/expect/App.java:6: error: package net.sf.expectit.matcher does not exist
import static net.sf.expectit.matcher.Matchers.regexp;
^
/home/thufir/NetBeansProjects/expect/src/main/java/expect/App.java:6: error: static import only from classes and interfaces
import static net.sf.expectit.matcher.Matchers.regexp;
^
/home/thufir/NetBeansProjects/expect/src/main/java/expect/App.java:24: error: cannot find symbol
Expect expect = new ExpectBuilder()
^
symbol:   class Expect
location: class App
/home/thufir/NetBeansProjects/expect/src/main/java/expect/App.java:24: error: cannot find symbol
Expect expect = new ExpectBuilder()
^
symbol:   class ExpectBuilder
location: class App
/home/thufir/NetBeansProjects/expect/src/main/java/expect/App.java:32: error: cannot find symbol
expect.expect(contains("Press Return to continue"));
^
symbol:   method contains(String)
location: class App
/home/thufir/NetBeansProjects/expect/src/main/java/expect/App.java:34: error: cannot find symbol
expect.expect(contains("forecast city code--"));
^
symbol:   method contains(String)
location: class App
/home/thufir/NetBeansProjects/expect/src/main/java/expect/App.java:36: error: cannot find symbol
expect.expect(contains("X to exit:"));
^
symbol:   method contains(String)
location: class App
11 errors
> Task :compileJava 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. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 11s
2 actionable tasks: 1 executed, 1 up-to-date
thufir@dur:~/NetBeansProjects/expect$ 
thufir@dur:~/NetBeansProjects/expect$ gradle -v
------------------------------------------------------------
Gradle 6.3
------------------------------------------------------------
Build time:   2020-03-24 19:52:07 UTC
Revision:     bacd40b727b0130eeac8855ae3f9fd9a0b207c60
Kotlin:       1.3.70
Groovy:       2.5.10
Ant:          Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM:          11.0.7 (AdoptOpenJDK 11.0.7+10)
OS:           Linux 5.4.0-29-generic amd64
thufir@dur:~/NetBeansProjects/expect$ 

法典:

package expect;
import java.util.logging.Logger;
import static net.sf.expectit.matcher.Matchers.contains;
import static net.sf.expectit.matcher.Matchers.eof;
import static net.sf.expectit.matcher.Matchers.regexp;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
public class App {
private final static Logger log = Logger.getLogger(App.class.getName());
public static void main(String[] args) {
new App().telnet();
}
private void telnet() {
log.info("foo");
Process process = Runtime.getRuntime().exec("telnet rainmaker.wunderground.com");
StringBuilder wholeBuffer = new StringBuilder();
Expect expect = new ExpectBuilder()
.withOutput(process.getOutputStream())
.withInputs(process.getInputStream())
.withEchoOutput(wholeBuffer)
.withEchoInput(wholeBuffer)
.withExceptionOnFailure()
.build();
expect.expect(contains("Press Return to continue"));
expect.sendLine();
expect.expect(contains("forecast city code--"));
expect.sendLine("SAN");
expect.expect(contains("X to exit:"));
expect.sendLine();
String response = wholeBuffer.toString();
System.out.println(response);
expect.close();
}
}

构建文件:

/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java project to get you started.
* For more details take a look at the Java Quickstart chapter in the Gradle
* User Manual available at https://docs.gradle.org/6.3/userguide/tutorial_java_projects.html
*/
plugins {
// Apply the java plugin to add support for Java
id 'java'
// Apply the application plugin to add support for building a CLI application.
id 'application'
}
repositories {
// Use jcenter for resolving dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
mavenCentral()
}
dependencies {
// This dependency is used by the application.
implementation 'com.google.guava:guava:28.2-jre'
// Use TestNG framework, also requires calling test.useTestNG() below
testImplementation 'org.testng:testng:7.0.0'  

// https://mvnrepository.com/artifact/net.sf.expectit/expectit-core
//    implementation 'net.sf.expectit' name 'expectit-core', version '0.9.0'
//    implementation 'net.sf.expectit' name: 'expectit-core', version: '0.9.0'

}
application {
// Define the main class for the application.
mainClassName = 'expect.App'
}
test {
// Use TestNG for unit tests
useTestNG()
}

运行:

package expectit;
import java.util.logging.Logger;
import static net.sf.expectit.matcher.Matchers.contains;
import static net.sf.expectit.matcher.Matchers.eof;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
public class App {
private final static Logger log = Logger.getLogger(App.class.getName());
public static void main(String[] args) throws IOException {
new App().telnet();
}
private void telnet() throws IOException {
log.info("foo");
Process process = Runtime.getRuntime().exec("telnet rainmaker.wunderground.com");
StringBuilder wholeBuffer = new StringBuilder();
net.sf.expectit.Expect expect = new net.sf.expectit.ExpectBuilder()
.withOutput(process.getOutputStream())
.withInputs(process.getInputStream())
.withEchoOutput(wholeBuffer)
.withEchoInput(wholeBuffer)
.withExceptionOnFailure()
.build();
expect.expect(contains("Press Return to continue"));
expect.sendLine();
expect.expect(contains("forecast city code--"));
expect.sendLine("SAN");
expect.expect(contains("X to exit:"));
expect.sendLine();
String response = wholeBuffer.toString();
System.out.println(response);
expect.close();
}
}

https://github.com/THUFIR/expectit

谢谢 SMAC89

最新更新