LaVOZs

The World’s Largest Online Community for Developers

'; java - Converting a kotlin project from pom.xml to build.gradle - LavOzs.Com

I am trying to convert my kotlin project from pom.xml to build.gradle with no success. I have a working pom.xml and when i compile with "mvn compile" it works perfect and runs tests. trying to build a new build.gradle to work with gradle with no success. pom.xml:

    <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>

        <groupId>com.mycompany.app</groupId>
        <artifactId>my-app</artifactId>
        <version>1.0-SNAPSHOT</version>

        <properties>
            <maven.compiler.source>1.7</maven.compiler.source>
            <maven.compiler.target>1.7</maven.compiler.target>
            <maven.compiler.release>11</maven.compiler.release>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <avro.version>1.9.1</avro.version>
            <kotlin.version>1.3.61</kotlin.version>
        </properties>

        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>3.0.0-M3</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.avro</groupId>
                    <artifactId>avro-maven-plugin</artifactId>
                    <version>${avro.version}</version>
                    <executions>
                        <execution>
                            <id>schemas</id>
                            <phase>generate-sources</phase>
                            <goals>
                                <goal>schema</goal>
                                <goal>protocol</goal>
                                <goal>idl-protocol</goal>
                            </goals>
                            <configuration>
                                <sourceDirectory>${project.basedir}/src/test/java/avro/</sourceDirectory>
                                <outputDirectory>${project.basedir}/src/test/java/</outputDirectory>
                                <stringType>String</stringType>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.jetbrains.kotlin</groupId>
                    <artifactId>kotlin-maven-plugin</artifactId>
                    <version>${kotlin.version}</version>
                    <executions>
                        <execution>
                            <id>compile</id>
                            <phase>compile</phase>
                            <goals>
                                <goal>compile</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>test-compile</id>
                            <phase>test-compile</phase>
                            <goals>
                                <goal>test-compile</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <jvmTarget>1.8</jvmTarget>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.1</version>
                    <executions>
                        <execution>
                            <id>compile</id>
                            <phase>compile</phase>
                            <goals>
                                <goal>compile</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>testCompile</id>
                            <phase>test-compile</phase>
                            <goals>
                                <goal>testCompile</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>3.1.0</version>
                    <configuration>
                        <filesets>
                            <fileset>
                                <directory>${basedir}/src/test/java/org/mashov/generated/</directory>
                            </fileset>
                        </filesets>
                    </configuration>
                </plugin>
            </plugins>
        </build>

        <dependencies>
            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter-api</artifactId>
                <version>5.0.0-M5</version>
            </dependency>
            <dependency>
                <groupId>com.github.dozermapper</groupId>
                <artifactId>dozer-core</artifactId>
                <version>6.5.0</version>
            </dependency>
            <dependency>
                <groupId>org.apache.avro</groupId>
                <artifactId>avro</artifactId>
                <version>${avro.version}</version>
            </dependency>
            <dependency>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-stdlib-jdk8</artifactId>
                <version>${kotlin.version}</version>
            </dependency>
            <dependency>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-test</artifactId>
                <version>${kotlin.version}</version>
            </dependency>
            <dependency>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-reflect</artifactId>
                <version>1.3.61</version>
            </dependency>
            <dependency>
                <groupId>io.github.microutils</groupId>
                <artifactId>kotlin-logging</artifactId>
                <version>1.7.7</version>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-jdk14</artifactId>
                <version>1.7.25</version>
            </dependency>
        </dependencies>
    </project>

new build.gradle:

import com.commercehub.gradle.plugin.avro.GenerateAvroJavaTask

group = 'com.mycompany.app'
version = '1.0-SNAPSHOT'

buildscript {
    ext.kotlin_version = '1.3.61'

    repositories {
        jcenter()
    }
    dependencies {
        classpath "com.commercehub.gradle.plugin:gradle-avro-plugin:0.17.0"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.junit.platform:junit-platform-gradle-plugin:1.2.0"
    }
}

apply plugin: "org.junit.platform.gradle.plugin"
apply plugin: "kotlin"
apply plugin: "java"
apply plugin: "maven-publish"
apply plugin: "com.commercehub.gradle.plugin.avro"

task generateAvro(type: GenerateAvroJavaTask) {
    source("src/test/java/avro/")
    outputDir = file("src/test/java/")
}

compileJava.source(generateAvro.outputs)

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

repositories {
    mavenCentral()
    mavenLocal()
    jcenter()
}

dependencies {
    // JAX-B dependencies for JDK 9+
    implementation "jakarta.xml.bind:jakarta.xml.bind-api:2.3.2"
    implementation "org.glassfish.jaxb:jaxb-runtime:2.3.2"

//    implementation 'org.junit.jupiter:junit-jupiter-api:5.0.0-M5'
    implementation 'com.github.dozermapper:dozer-core:6.5.0'
    implementation 'org.apache.avro:avro:1.9.1'
    implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.61'
    //implementation 'org.jetbrains.kotlin:kotlin-test:1.3.61'
    implementation 'org.jetbrains.kotlin:kotlin-reflect:1.3.61'
    implementation 'io.github.microutils:kotlin-logging:1.7.7'
    implementation 'org.slf4j:slf4j-jdk14:1.7.25'
    testImplementation 'io.kotlintest:kotlintest-runner-junit5:3.0.2'
    testImplementation 'org.jetbrains.kotlin:kotlin-test:1.3.61'
    //testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
    //testImplementation ('org.junit.jupiter:junit-jupiter-params:5.6.0')
    //testImplementation ('org.mockito:mockito-junit-jupiter:3.2.4')
    testImplementation("org.junit.platform:junit-platform-launcher:1.6.0")
    testRuntimeOnly ('org.junit.jupiter:junit-jupiter-engine:5.6.0')

    test.useJUnitPlatform() // fix "test events not received" bug in IDEA

}

test {
    useJUnitPlatform()
    testLogging {
        events("passed", "skipped", "failed")
    }
}

sourceCompatibility = '1.8'

publishing {
    publications {
        maven(MavenPublication) {
            from(components.java)
        }
    }
}

what am i doing wrong? how can i build the project with running the tests with gradle?

  1. navigate to pom file directory
  2. run gradle init This will convert the Maven build to a Gradle build, generating a settings.gradle
  3. this message should appear: Found a Maven build. Generate a Gradle build from this? (default: yes) [yes, no]
  4. press yes

tasted on your pom file

with

------------------------------------------------------------
Gradle 5.6.2
------------------------------------------------------------

Build time:   2019-09-05 16:13:54 UTC
Revision:     55a5e53d855db8fc7b0e494412fc624051a8e781

Kotlin:       1.3.41
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.14 compiled on March 12 2019
JVM:          11.0.1 (Oracle Corporation 11.0.1+13)
OS:           Mac OS X 10.15.3 x86_64

and

Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-24T21:41:47+03:00)
Maven home: /Users/naortedgi/.sdkman/candidates/maven/current
Java version: 11.0.1, vendor: Oracle Corporation, runtime: /Users/naortedgi/.sdkman/candidates/java/11.0.1-open
Default locale: en_IL, platform encoding: UTF-8
OS name: "mac os x", version: "10.15.3", arch: "x86_64", family: "mac"
Related
Create ArrayList from array
How do I call one constructor from another in Java?
How do I read / convert an InputStream into a String in Java?
How to add local jar files to a Maven project?
How do I convert a String to an int in Java?
How to add local .jar file dependency to build.gradle file?
Mixing Java And Kotlin In Gradle Project, Kotlin Cannot Find Java Class
What is the equivalent of Java static methods in Kotlin?
Android - Kotlin files are present in apk after compilation
pom.xml Maven configuration to run JUnit 4 + JUnit 5 Jupiter tests in mixed Java + Kotlin project