使用Gradle自动创建Java项目结构
来源:互联网 发布:excel表格数据分列 编辑:程序博客网 时间:2024/05/24 03:05
D:\N3verL4nd\Desktop\java>tree卷 本地磁盘 的文件夹 PATH 列表卷序列号为 00000200 0006:08B0D:.├─.gradle│ ├─3.4.1│ │ ├─file-changes│ │ └─taskHistory│ └─buildOutputCleanup├─gradle│ └─wrapper└─src ├─main │ └─java └─test └─javaD:\N3verL4nd\Desktop\java>
通过使用:
gradle init --type java-library
gradle init --type支持的几个选项:
'basic', 'groovy-library', 'java-application', 'java-library', 'pom', 'scala-library'
我们可以快速建立一个java开发项目目录。
src/main/java目录包含了项目的源代码。
src/main/resources目录包含了项目的资源(如属性文件)。
src/test/java目录包含了测试类。
src/test/resources目录包含了测试资源。所有我们构建生成的文件都会在build目录下被创建,这个目录涵盖了以下的子目录
classes目录包含编译过的.class文件。
libs目录包含构建生成的jar或war文件。
src\main\java与src\test\java生成的*.java文件可以删除。
默认生成的build.gradle为:
/* * This build file was generated by the Gradle 'init' task. * * 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/3.4.1/userguide/java_library_plugin.html */// Apply the java-library plugin to add support for Java Libraryapply plugin: 'java-library'// In this section you declare where to find the dependencies of your projectrepositories { // Use jcenter for resolving your dependencies. // You can declare any Maven/Ivy/file repository here. jcenter()}dependencies { // 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:20.0' // Use JUnit test framework testImplementation 'junit:junit:4.12'}
我们可以对它做如下修改,来生成一个Hello World程序。
apply plugin: 'java'jar {manifest {attributes 'Main-Class': 'aa.bb.cc.HelloWorld'}}
使用gradle tasks可以得到一个可运行任务及其描述的完整列表
这是一个很好的方式,不需要阅读构建脚本,就能对你的项目进行大致的浏览
gradle中几个常见的任务:
assemble任务会编译程序中的源代码,并打包生成Jar文件,这个任务不执行单元测试。
build任务会执行一个完整的项目构建。
clean任务会删除构建目录。
compileJava任务会编译程序中的源代码。
我们编写个简单的HelloWorld程序:
package aa.bb.cc;public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); }}
D:\N3verL4nd\Desktop\java\src\main\java>tree /f卷 本地磁盘 的文件夹 PATH 列表卷序列号为 00000200 0006:08B0D:.└─xiya HelloWorld.java如上,我们的*.java文件在java目录下的xiya子目录下,而*.java源文件是这样写的:package aa.bb.cc;
生成的结构:
D:\N3verL4nd\Desktop\java\build>tree /f卷 本地磁盘 的文件夹 PATH 列表卷序列号为 00000200 0006:08B0D:.├─classes│ └─main│ └─aa│ └─bb│ └─cc│ HelloWorld.class可见,src\main\java文件夹下的目录结构只是为了对源文件分类。
参考:
https://docs.gradle.org/current/userguide/build_init_plugin.html
- 使用Gradle自动创建Java项目结构
- 使用Gradle创建Java项目
- Idea 使用 Gradle 插件创建 Java 项目
- 有关使用gradle创建java web项目
- 使用IDEA及Gradle创建Java项目
- 使用gradle创建java项目2
- Windows下使用Gradle创建Java项目
- 使用 Gradle 创建 Java Web 项目整理
- Gradle创建项目目录结构
- Gradle创建项目目录结构
- Gradle 创建java项目
- 使用gradle初始化(创建)java的目录结构
- 使用idea创建gradle项目
- 使用gradle 创建springboot项目
- 使用gradle创建Akka项目
- 使用Gradle创建web项目
- 使用gradle和eclipse创建java web项目
- 初学使用Gradle创建一个Java项目总结
- 树莓派学习笔记(1):入手树莓派
- 使用炫彩界面库完美实现窗口阴影效果
- clone()方法(浅复制、深复制)
- 我为什这么强烈而又坚定的推荐你做TPS云集品
- 题目1040:Prime Number
- 使用Gradle自动创建Java项目结构
- NIO
- linux 下的时间获取函数
- 原生JS实现AJAX的思路
- 内存分配之分段管理以及分段和分页的区别
- js的this用法
- js正则表达式使用变量
- Struts2入门详解(二)
- JS数据结构与算法(一)