$ gradle wrapper --gradle-version 6.0.1
After this job completes, you will notice a few new files. The two scripts are in the settle of the booklet, while the wrapping jar and properties files have been added to a raw gradle/wrapper
folder .
└──└── gradlew └── gradlew.bat └── gradle └── wrapper └── gradle-wrapper.jar └── gradle-wrapper.properties
The Gradle Wrapper is now available for building your plan. Add it to your version control arrangement, and everyone that clones your project can build it just the lapp. It can be used in the accurate lapp direction as an install adaptation of Gradle. Run the negligee script to perform the construct task, merely like you did previously :
./gradlew build
The first time you run the wrapping for a pin down version of Gradle, it downloads and caches the Gradle binaries for that interpretation. The Gradle Wrapper files are designed to be committed to source see so that anyone can build the project without having to first install and configure a particular interpretation of Gradle.
Reading: Building Java Projects with Gradle
At this stagecoach, you will have built your code. You can see the results here :
build ├── classes │ └── main │ └── hello │ ├── Greeter.class │ └── HelloWorld.class ├── dependency-cache ├── libs │ └── gs-gradle-0.1.0.jar └── tmp └── jar └── MANIFEST.MF
Included are the two expected class files for Greeter
and HelloWorld
, angstrom well as a JAR file. Take a quick peek :
$ jar tvf build/libs/gs-gradle-0.1.0.jar 0 Fri May 30 16:02:32 CDT 2014 META-INF/ 25 Fri May 30 16:02:32 CDT 2014 META-INF/MANIFEST.MF 0 Fri May 30 16:02:32 CDT 2014 hello/ 369 Fri May 30 16:02:32 CDT 2014 hello/Greeter.class 988 Fri May 30 16:02:32 CDT 2014 hello/HelloWorld.class
The class files are bundled up. It ’ s important to note, that even though you declared joda-time as a dependence, the library international relations and security network ’ thyroxine included here. And the JAR file international relations and security network ’ t runnable either.
To make this code runnable, we can use gradle ’ sulfur application
plugin. Add this to your build.gradle
file .
apply plugin: 'application' mainClassName = 'hello.HelloWorld'
then you can run the app !
$ ./gradlew run :compileJava UP-TO-DATE :processResources UP-TO-DATE :classes UP-TO-DATE :run The current local time is: 16:16:20.544 Hello world! BUILD SUCCESSFUL Total time: 3.798 secs
To bundle up dependencies requires more think. For exemplar, if we were building a WAR file, a format normally associated with pack in 3rd party dependencies, we could use gradle ’ s WAR plugin. If you are using Spring Boot and want a runnable JAR charge, the spring-boot-gradle-plugin is quite handy. At this stage, gradle doesn ’ t know adequate about your system to make a choice. But for nowadays, this should be enough to get started using gradle .
To wrap things up for this guide, here is the complete build.gradle
file :
build.gradle
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'application'
mainClassName = 'hello.HelloWorld'
// tag::repositories[]
repositories {
mavenCentral()
}
// end::repositories[]
// tag::jar[]
jar {
archiveBaseName = 'gs-gradle'
archiveVersion = '0.1.0'
}
// end::jar[]
// tag::dependencies[]
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
implementation "joda-time:joda-time:2.2"
testImplementation "junit:junit:4.12"
}
// end::dependencies[]
// tag::wrapper[]
// end::wrapper[]
There are many start/end comments embedded here. This makes it possible to extract bits of the build file into this guide for the detailed explanations above. You don’t need them in your production build file. |