1

I've used gradle plugin to generate pom.xml.

following correspond documentation I've added to may project into build.gradle file next changes:

task writePom {
    doLast {
        pom {
            project {
                inceptionYear '2008'
                licenses {
                    license {
                        name 'The Apache Software License, Version 2.0'
                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                        distribution 'repo'
                    }
                }
            }
        }.writeTo("pom.xml")
    }
}

after that I used gradle writePom and as result I've got generated pom.xml in my project root directory.

The issue is I can not build project using the pom.xml because of:

> maven clean install

[ERROR] /Users/XXX/Documents/projects/workspace/THE_PROJECT/src/main/java/CLASS_PACKAGE/THE_CLASS.java:[45,38] diamond operator is not supported in -source 1.5

(use -source 7 or higher to enable diamond operator)

The issue reason is completely clear. My pom.xml should use valid java version but the java version isn't generated in it.

How should I configure the plugin (for gradle) to generate pom.xml with specified java version?

Add more details

build.gradle

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath group: 'pl.allegro.tech.build', name: 'axion-release-plugin', version: '1.7.1'
        classpath 'org.hidetake:gradle-ssh-plugin:1.1.3'
    }
}

plugins {
    id "nebula.provided-base" version "3.0.3"
}

apply plugin: 'java'
apply plugin: 'java-library'
apply plugin: 'groovy'
apply plugin: 'osgi'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'jacoco'
apply plugin: 'signing'
apply plugin: 'pl.allegro.tech.build.axion-release'
apply plugin: 'nebula.optional-base'
apply from: 'gradle/dist.gradle'

group = 'org.mnode.ical4j'
description = '''
A Java library for reading and writing iCalendar (*.ics) files
'''

sourceCompatibility = 1.7
targetCompatibility = 1.7
ext {
    slf4jVersion = '1.7.10'
}

repositories {
    mavenCentral()
}

dependencies {
    api "org.slf4j:slf4j-api:$slf4jVersion",
        'commons-codec:commons-codec:1.9',
        'org.apache.commons:commons-lang3:3.3.2',
        'org.apache.commons:commons-collections4:4.0',
        'org.threeten:threetenbp:1.3.3'

    compile 'org.codehaus.groovy:groovy-all:2.3.2', optional

    compileOnly 'biz.aQute.bnd:bndlib:2.3.0'

    testImplementation 'org.codehaus.groovy:groovy-all:2.3.2',
        'org.spockframework:spock-core:0.7-groovy-2.0',
        'commons-io:commons-io:2.4',
        'org.ccil.cowan.tagsoup:tagsoup:1.2.1',
        "org.slf4j:slf4j-log4j12:$slf4jVersion"
}

jacocoTestReport {
    reports {
        xml.enabled true
        html.enabled false
    }
}

javadoc {
    if (JavaVersion.current().isJava8Compatible()) {
        options.addStringOption('Xdoclint:none', '-quiet')
    }
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from 'build/docs/javadoc'
}

task sourcesJar(type: Jar) {
    from sourceSets.main.allSource
    classifier = 'sources'
}

jar {
    manifest {
        instruction 'Import-Package', 'groovy.*;resolution:=optional, org.codehaus.groovy*;resolution:=optional, *'
    }
}

artifacts {
    archives jar
    archives javadocJar
    archives sourcesJar
}

signing {
    required { isReleaseVersion && gradle.taskGraph.hasTask("uploadArchives") }
    sign configurations.archives
}

scmVersion {
    tag {
        prefix = 'ical4j'
    }
    versionCreator 'versionWithBranch'
    branchVersionCreator = [
        'master': 'simple'
    ]
}
version = scmVersion.version

ext {
    isReleaseVersion = !version.endsWith("SNAPSHOT")
}

task writePom {
    doLast {
        pom {
            project {
                inceptionYear '2008'
                licenses {
                    license {
                        name 'The Apache Software License, Version 2.0'
                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                        distribution 'repo'
                    }
                }
            }
        }.writeTo("pom.xml")
    }
}
Sergii
  • 7,044
  • 14
  • 58
  • 116

1 Answers1

1

You can specify the Java version with the target command:

targetCompatibility = '1.7'

Try with this code:

apply plugin: 'java'
compileJava {
  sourceCompatibility = '1.7'
}

For more info visit this post:

how specify the required java version in a gradle build?

Javier C.
  • 7,859
  • 5
  • 41
  • 53
  • I see in your proposition only property, not command. Have you checked it? Can you please provide command? (my gradle build file has this property and it is main reason, why gradle builds without failing) – Sergii Oct 09 '17 at 15:40
  • @Sergii I edited my post, try with compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 } – Javier C. Oct 09 '17 at 15:42
  • Thanks for your answer and comments, checking result... `compileJava` - pom generated without changes. If I use `compileOptions` build fails in `gradle` stage. Trying to get more info and set properties correctly... – Sergii Oct 09 '17 at 15:55
  • @Sergii Can you put the code of your build.gradle file?thanks – Javier C. Oct 09 '17 at 15:58
  • [compileOptions](https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/compile/CompileOptions.html) does not have properties for java version, but i'm frying to find how to set it in 4.2.1 version – Sergii Oct 09 '17 at 15:59
  • @Sergii I edited my post: apply plugin: 'java' compileJava { sourceCompatibility = '1.7' } Can you check? – Javier C. Oct 09 '17 at 16:03
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/156282/discussion-between-sergii-and-trisquel). – Sergii Oct 09 '17 at 16:09
  • thanks, i've checked it also. It doesn't work any way, sorry. – Sergii Oct 09 '17 at 16:14