当我添加
compile group: 'com.azure', name: 'azure-cosmos', version: '4.0.1-beta.4'
我在build.gradle
的Jar文件中的依赖项将不再执行。
我基本上是使用gradle init
从头开始创建一个新项目,并添加此依赖项。
当我运行java -jar <jarFile>
没有依赖项,它可以正常工作并打印“ Hello World”。
我在这里想念什么?
我当前的build.gradle
如下:
/*
* 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.4.1/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()
}
dependencies {
// This dependency is used by the application.
implementation 'com.google.guava:guava:28.2-jre'
// https://mvnrepository.com/artifact/com.microsoft.azure/azure-cosmos
compile group: 'com.azure', name: 'azure-cosmos', version: '4.0.1-beta.4'
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
}
jar {
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
manifest {
attributes (
'Main-Class': 'gradle.cosmos.example.App'
)
}
}
应用类如下:
/*
* This Java source file was generated by the Gradle 'init' task.
*/
package gradle.cosmos.example;
public class App {
public String getGreeting() {
return "Hello world.";
}
public static void main(String[] args) {
System.out.println(new App().getGreeting());
}
}
答案 0 :(得分:0)
这将起作用:
plugins {
id 'java'
id 'application'
}
repositories {
jcenter()
}
dependencies {
implementation 'com.google.guava:guava:28.2-jre'
compile group: 'com.azure', name: 'azure-cosmos', version: '4.0.1-beta.4'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
jar {
manifest {
attributes(
'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
'Main-Class': 'gradle.cosmos.example.App'
)
}
}