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 
blog comments powered by Disqus

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
String Vs StringBuffer
We know that String is immutable object. We can not change the value of a String object once it is initiated. If we try to change the value of the existing String object then it creates new object rather than changing the value of the existing object. So incase, we are going to do more modificatios on String, then use StringBuffer. StringBuffer updates the existing objects value, rather creating new object.
Famous Quotations
I respect faith, but doubt is what gets you an education.
-- Wilson Mizner

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 java2novice@gmail.com or you can comment on the page.

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.