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
Difference between Enumeration and Iterator
The functionality of Enumeration and the Iterator are same. You can get remove() from Iterator to remove an element, while while Enumeration does not have remove() method. Using Enumeration you can only traverse and fetch the objects, where as using Iterator we can also add and remove the objects. So Iterator can be useful if you want to manipulate the list and Enumeration is for read-only access.
Famous Quotations
Before you go and criticize the younger generation, just remember who raised them.
-- Unknown Author

About Author

I'm Nataraja Gootooru, programmer by profession and passionate about technologies. All examples given here are as simple as possible to help beginners. The source code is compiled and tested in my dev environment.

If you come across any mistakes or bugs, please email me to [email protected].

Most Visited Pages

Other Interesting Sites

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