我试图将我的kotlin项目从pom.xml转换为build.gradle,但没有成功。 我有一个可运行的pom.xml,当我使用“ mvn编译”进行编译时,它可以完美运行并运行测试。 试图建立一个新的build.gradle以与gradle一起使用而没有成功。 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>
新建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)
}
}
}
我在做什么错?如何通过gradle运行测试来构建项目?
答案 0 :(得分:0)
gradle init
这会将Maven构建转换为Gradle构建,生成settings.gradle
Found a Maven build. Generate a Gradle build from this? (default: yes) [yes, no]
已放入您的pom文件
与
------------------------------------------------------------
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
和
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"