JAVA EXAMPLE PROGRAMS

JAVA EXAMPLE PROGRAMS

Publish Your Article Here

How to create java project in gradle?


This page gives an introduction to gradle java project, include java plugin in your gradle configuration file, which adds all required tasks by default.

apply plugin: 'java'

Folder structure should be similar to maven java project folder structure.

src/main/java
src/test/java
src/main/resources
src/test/resources
build – all output files will be created here.
build/lib

Add below configuration to define external dependencies using maven.

repositories {
        mavenCentral()
}

dependencies {
        compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
        testCompile group: 'junit', name: 'junit', version: '4.+'
}

The Java plugin by default adds many properties to your project. You are allowed to change these values. Here is an example to customize your MANIFEST.MF file:

sourceCompatibility = 1.5
version = '1.0'
jar {
        manifest {
                attributes 'Implementation-Title': 'Gradle Quickstart',
                          	        'Implementation-Version': version
        }
}

Here is the complete sample java project configuration using gradle:

apply plugin: 'java'
apply plugin: 'eclipse'
sourceCompatibility = 1.5
version = '1.0'
jar {
        manifest {
                attributes 'Implementation-Title': 'Gradle Quickstart',
                           'Implementation-Version': version
                }
}
repositories {
        mavenCentral()
}
dependencies {
        compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
        testCompile group: 'junit', name: 'junit', version: '4.+'
}
test {
        systemProperties 'property': 'value'
}
uploadArchives {
        repositories {
                flatDir {
                        dirs 'repos'
                }
        }
}

Reference: Gradle Documentation

<< Previous Program 

Gradle configuration examples

  1. Gradle Installation Steps
  2. What is gradle project and task
  3. What is build.gradle file?
  4. How to avoid gradle log messages?
  5. How to define default tasks in Gradle?
  6. How to list all gradle tasks?
  7. How to list gradle project properties?
  8. How to declare a task that depends on other task?
  9. How to create dynamic tasks in Gradle?
  10. How to exclude a task in gradle?
  11. How to create java project in gradle?
Knowledge Centre
wait Vs sleep methods
sleep(): It is a static method on Thread class. It makes the current thread into the "Not Runnable" state for specified amount of time. During this time, the thread keeps the lock (monitors) it has acquired.

wait(): It is a method on Object class. It makes the current thread into the "Not Runnable" state. Wait is called on a object, not a thread. Before calling wait() method, the object should be synchronized, means the object should be inside synchronized block. The call to wait() releases the acquired lock.
Famous Quotations
Millions long for immortality who do not know what to do with themselves on a rainy Sunday afternoon.
-- Susan Erz

About Author

Most Visited Pages

Other Interesting Sites

Reference: Java™ Platform Standard Ed. 7 - API Specification | Java is registered trademark of Oracle.
Privacy Policy | Copyright © 2017 by Nataraja Gootooru. All Rights Reserved.