gradle init:java和java_library之间的区别是什么?
我调查了一下 gradle init –type java-application 和 gradle init –type java_library 两者之间的区别并记录下来。
Gradle使用了4.0版本。
build.gradle的差异
应用插件的区别
type違いjava-applicationapply plugin: ‘java’java-libraryapply plugin: ‘java-library’
dependencies的差异 (Dependencies de chayi)
type違いjava-applicationcompile ‘com.google.guava:guava:21.0’
testCompile ‘junit:junit:4.12’java-libraryapi ‘org.apache.commons:commons-math3:3.6.1’
implementation ‘com.google.guava:guava:21.0’
testImplementation ‘junit:junit:4.12’
testCompile ‘junit:junit:4.12’java-libraryapi ‘org.apache.commons:commons-math3:3.6.1’
implementation ‘com.google.guava:guava:21.0’
testImplementation ‘junit:junit:4.12’
主类名称
type違いjava-application-mainClassName = ‘App’java-library未定義
根据差异输出
--- java/build.gradle 2017-06-25 18:05:15.000000000 +0900
+++ ./java_library/build.gradle 2017-06-25 18:05:34.000000000 +0900
@@ -1,16 +1,13 @@
/*
* This build 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 guide available at https://docs.gradle.org/4.0/userguide/tutorial_java_projects.html
+ * This generated file contains a sample Java Library project to get you started.
+ * For more details take a look at the Java Libraries chapter in the Gradle
+ * user guide available at https://docs.gradle.org/4.0/userguide/java_library_plugin.html
*/
-// Apply the java plugin to add support for Java
-apply plugin: 'java'
-
-// Apply the application plugin to add support for building an application
-apply plugin: 'application'
+// Apply the java-library plugin to add support for Java Library
+apply plugin: 'java-library'
// In this section you declare where to find the dependencies of your project
repositories {
@@ -20,13 +17,13 @@
}
dependencies {
- // This dependency is found on compile classpath of this component and consumers.
- compile 'com.google.guava:guava:21.0'
+ // This dependency is exported to consumers, that is to say found on their compile classpath.
+ api 'org.apache.commons:commons-math3:3.6.1'
+
+ // This dependency is used internally, and not exposed to consumers on their own compile classpath.
+ implementation 'com.google.guava:guava:21.0'
// Use JUnit test framework
- testCompile 'junit:junit:4.12'
+ testImplementation 'junit:junit:4.12'
}
-// Define the main class for the application
-mainClassName = 'App'
-
文件输出
如果使用gradle init –type java-application这个命令的话,在中文中是这样的。
.
|-- build.gradle
|-- gradle
| `-- wrapper
| |-- gradle-wrapper.jar
| `-- gradle-wrapper.properties
|-- gradlew
|-- gradlew.bat
|-- settings.gradle
`-- src
|-- main
| `-- java
| `-- App.java
`-- test
`-- java
`-- AppTest.java
如果使用gradle init –type java-library命令
.
|-- build.gradle
|-- gradle
| `-- wrapper
| |-- gradle-wrapper.jar
| `-- gradle-wrapper.properties
|-- gradlew
|-- gradlew.bat
|-- settings.gradle
`-- src
|-- main
| `-- java
| `-- Library.java
`-- test
`-- java
`-- LibraryTest.java
发现产能
diff -ur java/.gradle/buildOutputCleanup/cache.properties java_library/.gradle/buildOutputCleanup/cache.properties
--- java/.gradle/buildOutputCleanup/cache.properties 2017-06-25 18:05:05.000000000 +0900
+++ java_library/.gradle/buildOutputCleanup/cache.properties 2017-06-25 18:05:34.000000000 +0900
@@ -1,2 +1,2 @@
-#Sun Jun 25 18:05:05 JST 2017
+#Sun Jun 25 18:05:34 JST 2017
gradle.version=4.0
diff -ur java/build.gradle java_library/build.gradle
--- java/build.gradle 2017-06-25 18:05:15.000000000 +0900
+++ java_library/build.gradle 2017-06-25 18:05:34.000000000 +0900
@@ -1,16 +1,13 @@
/*
* This build 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 guide available at https://docs.gradle.org/4.0/userguide/tutorial_java_projects.html
+ * This generated file contains a sample Java Library project to get you started.
+ * For more details take a look at the Java Libraries chapter in the Gradle
+ * user guide available at https://docs.gradle.org/4.0/userguide/java_library_plugin.html
*/
-// Apply the java plugin to add support for Java
-apply plugin: 'java'
-
-// Apply the application plugin to add support for building an application
-apply plugin: 'application'
+// Apply the java-library plugin to add support for Java Library
+apply plugin: 'java-library'
// In this section you declare where to find the dependencies of your project
repositories {
@@ -20,13 +17,13 @@
}
dependencies {
- // This dependency is found on compile classpath of this component and consumers.
- compile 'com.google.guava:guava:21.0'
+ // This dependency is exported to consumers, that is to say found on their compile classpath.
+ api 'org.apache.commons:commons-math3:3.6.1'
+
+ // This dependency is used internally, and not exposed to consumers on their own compile classpath.
+ implementation 'com.google.guava:guava:21.0'
// Use JUnit test framework
- testCompile 'junit:junit:4.12'
+ testImplementation 'junit:junit:4.12'
}
-// Define the main class for the application
-mainClassName = 'App'
-
Binary files java/gradle/wrapper/gradle-wrapper.jar and java_library/gradle/wrapper/gradle-wrapper.jar differ
diff -ur java/gradle/wrapper/gradle-wrapper.properties java_library/gradle/wrapper/gradle-wrapper.properties
--- java/gradle/wrapper/gradle-wrapper.properties 2017-06-25 18:05:05.000000000 +0900
+++ java_library/gradle/wrapper/gradle-wrapper.properties 2017-06-25 18:05:34.000000000 +0900
@@ -1,4 +1,4 @@
-#Sun Jun 25 18:05:05 JST 2017
+#Sun Jun 25 18:05:34 JST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
diff -ur java/settings.gradle java_library/settings.gradle
--- java/settings.gradle 2017-06-25 18:05:15.000000000 +0900
+++ java_library/settings.gradle 2017-06-25 18:05:34.000000000 +0900
@@ -15,4 +15,4 @@
include 'services:webservice'
*/
-rootProject.name = 'java'
+rootProject.name = 'java_library'
Only in java/src/main/java: App.java
Only in java_library/src/main/java: Library.java
Only in java/src/test/java: AppTest.java
Only in java_library/src/test/java: LibraryTest.java