I'm working on a Jetbrains Hyperskill track KOTLIN, it's my third project and I never had this kind of problem. I found this post (here), and tried their suggestions (Which are the same that JetBrains give on their wiki/FAQ), but didn't work.
The project is: Unit Converter (Heavy Duty Step 4/5)
Here is my code:
package converter
fun main() {
loopcheck@ while (true) {
var conversion: Double
print("Enter what you want to convert (or exit): ")
val userInput = readln()
if (userInput == "exit") break@loopcheck
val (originalNumber, originalUnit, convertedUnit) = userInputSplit(userInput)
// Validating inputs/Enums exception checks
if (originalNumber == null) {
println("Wrong number")
continue@loopcheck
}
if (originalUnit == null && convertedUnit != null) {
println("Conversion from ??? to $convertedUnit is impossible")
continue@loopcheck
}
if (originalUnit != null && convertedUnit == null) {
println("Conversion from $originalUnit to ??? is impossible")
continue@loopcheck
}
if (originalUnit == null && convertedUnit == null) {
println("Conversion from ??? to ??? is impossible")
continue@loopcheck
}
if (originalUnit != null && convertedUnit != null) {
if (originalUnit.type != convertedUnit.type) {
println("Conversion from ${originalUnit.plural} to ${convertedUnit.plural} is impossible")
continue@loopcheck
} else {
// Conversion Calculus
conversion = originalNumber * originalUnit.ratio / convertedUnit.ratio
// Check if the units are singular or plural
val preUnitCheck = if (originalNumber == 1.0) originalUnit.singular else originalUnit.plural
val postUnitCheck = if (conversion == 1.0) convertedUnit.singular else convertedUnit.plural
// Prints final text
println("$originalNumber $preUnitCheck is $conversion $postUnitCheck")
}
}
}
}
// Function to organize userInput in 3 variables: Number Unit1 Unit2
fun userInputSplit(userInput: String): Triple<Double?, Unidade?, Unidade?> {
val userInputArray = userInput.lowercase().split(" ")
val originalNumber = try {
userInputArray[0].toDouble()
} catch (e: NumberFormatException) { null }
val originalUnit = try {
getUnit(userInputArray[1])
} catch (e: IllegalArgumentException) { null }
val convertedUnit = try {
getUnit(userInputArray[2])
} catch (e: IllegalArgumentException) { null }
return Triple(originalNumber, originalUnit, convertedUnit)
}
// Function to set constant from Unidade for conversion based from User Input.
fun getUnit(unit: String): Unidade =
when (unit) {
"m", "meter", "meters" -> Unidade.METER
"km", "kilometer", "kilometers" -> Unidade.KILOMETER
"cm", "centimeter", "centimeters" -> Unidade.CENTIMETER
"mm", "millimeter", "millimeters" -> Unidade.MILLIMETER
"mi", "mile", "miles" -> Unidade.MILE
"yd", "yard", "yards" -> Unidade.YARD
"ft", "foot", "feet" -> Unidade.FOOT
"in", "inch", "inches" -> Unidade.INCH
"g", "gram", "grams" -> Unidade.GRAM
"kg", "kilogram", "kilograms" -> Unidade.KILOGRAM
"mg", "milligram", "milligrams" -> Unidade.MILLIGRAM
"lb", "pound", "pounds" -> Unidade.POUND
"oz", "ounce", "ounces" -> Unidade.OUNCE
// "degree celsius", "degrees celsius", "celsius", "dc", "c" -> Unit.CELSIUS
// "degree fahrenheit", "degrees fahrenheit", "fahrenheit", "df", "f" -> Unit.FAHRENHEIT
// "kelvin", "kelvins", "k" -> Unit.Kelvin
else -> throw IllegalArgumentException ("Wrong Unit. Try Again.")
}
enum class Unidade (val short: String,
val singular: String,
val plural: String,
val ratio: Double,
val type: String
) {
METER("m","meter", "meters", 1.0, "Length"),
KILOMETER("km","kilometer", "kilometers", 1000.0, "Length"),
CENTIMETER("cm","centimeter", "centimeters", 0.01, "Length"),
MILLIMETER("mm", "millimeter", "millimeters", 0.001, "Length"),
MILE("mi","mile", "miles", 1609.35, "Length"),
YARD("yd","yard", "yards", 0.9144, "Length"),
FOOT("ft","foot", "feet", 0.3048, "Length"),
INCH("in","inch", "inches", 0.0254, "Length"),
GRAM("g", "gram", "grams", 1.0, "Weight"),
KILOGRAM("kg", "kilogram", "kilograms", 1000.0, "Weight"),
MILLIGRAM("mg", "milligram", "milligrams", 0.001, "Weight"),
POUND("lb", "pound", "pounds", 453.592, "Weight"),
OUNCE("oz","ounce", "ounces", 28.3495, "Weight");
//CELSIUS("degree Celsius", "degrees Celsius", 1.0, "Temperature"),
//KELVIN("Kelvin", "Kelvins", 1.0, "Temperature"),
//FAHRENHEIT("degree Fahrenheit", "degrees Fahrenheit", 1.0, "Temperature")
}
Every time I try to check my code with Hyperskill, this happens now:
Failed to launch checking
FAILURE: Build failed with an exception.
- What went wrong: Execution failed for task ':Unit_Converter-task:compileTestKotlin'.
Error while evaluating property 'filteredArgumentsMap' of task ':Unit_Converter-task:compileTestKotlin' Could not resolve all files for configuration ':Unit_Converter-task:testCompileClasspath'. > Could not find com.github.hyperskill:hs-test:release-SNAPSHOT. Searched in the following locations: - https://repo.maven.apache.org/maven2/com/github/hyperskill/hs-test/release-SNAPSHOT/maven-metadata.xml - https://repo.maven.apache.org/maven2/com/github/hyperskill/hs-test/release-SNAPSHOT/hs-test-release-SNAPSHOT.pom - https://jitpack.io/com/github/hyperskill/hs-test/release-SNAPSHOT/maven-metadata.xml - https://jitpack.io/com/github/hyperskill/hs-test/release-SNAPSHOT/hs-test-release-v8-g6845035-132-v8-g6845035-132.pom Required by: project :Unit_Converter-task
- Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
- Get more help at https://help.gradle.org
BUILD FAILED in 16s
Task :Unit_Converter-task:compileKotlin Task :Unit_Converter-task:compileJava NO-SOURCE Task :Unit_Converter-task:processResources NO-SOURCE Task :Unit_Converter-task:classes UP-TO-DATE Task :util:compileKotlin NO-SOURCE Task :util:compileJava NO-SOURCE Task :util:processResources NO-SOURCE Task :util:classes UP-TO-DATE Task :util:compileTestKotlin NO-SOURCE Task :util:compileTestJava NO-SOURCE Task :util:processTestResources NO-SOURCE Task :util:testClasses UP-TO-DATE Task :Unit_Converter-task:compileTestKotlin FAILED 2 actionable tasks: 2 executed
CodePudding user response:
Open the build.gradle file in the root directory of your JetBrains Academy project and replace testImplementation 'com.github.hyperskill:hs-test:release-SNAPSHOT'
with testImplementation 'com.github.hyperskill:hs-test:master-SNAPSHOT'
.
CodePudding user response:
After reaching JETBRAINS support we did some actions. In the end, the problem was solved. Down below the steps taken.
1st try:
Open build.gradle in your project folder and replace testImplementation 'com.github.hyperskill:hs-test:release-SNAPSHOT' with testImplementation 'com.github.hyperskill:hs-test:master-SNAPSHOT'
The build output after the modification changed to a different error message.
Compilation Failed e: C:\Users\rafam\IdeaProjects\Unit Converter\Unit Converter\task\test\Task2Test.kt: (6, 1): Conflicting overloads: public fun authorsCase(input: String, isPrivate: Boolean = ...): TestCase defined in root package in file Task2Test.kt, public fun authorsCase(input: String, isPrivate: Boolean = ...): TestCase defined in root package in file Task4Test.kt e: C:\Users\rafam\IdeaProjects\Unit Converter\Unit Converter\task\test\Task2Test.kt: (6, 81): Unresolved reference: Authors e: C:\Users\rafam\IdeaProjects\Unit Converter\Unit Converter\task\test\Task2Test.kt: (6, 90): Unresolved reference: solve e: C:\Users\rafam\IdeaProjects\Unit Converter\Unit Converter\task\test\Task2Test.kt: (11, 13): Overload resolution ambiguity: public fun authorsCase(input: String, isPrivate: Boolean = ...): TestCase defined in root package in file Task2Test.kt public fun authorsCase(input: String, isPrivate: Boolean = ...): TestCase defined in root package in file Task4Test.kt ...
FAILURE: Build failed with an exception.
- What went wrong: Execution failed for task ':Unit_Converter-task:compileTestKotlin'.
After this error, Jetbrains support suggested new steps:
Please try re-creating the project by following the steps below: Go to the affected JetBrains Academy project’s directory and move it somewhere else or make a backup.
On the Welcome Screen of your IDE, go to the My Courses tab. Highlight the affected project and click ✕. Select Remove Course.
Start a JetBrains Academy project by going to the JetBrains Academy tab in File | Learn and Teach | Browse Courses.
After that, please ensure that JDK 17 is selected as Gradle JVM in Settings/Preferences | Build, Execution, Deployment | Build Tools | Gradle and as Project SDK in File | Project Structure.
I've changed and updated everything as suggested and the build output changed AGAIN:
Failed to launch checking
FAILURE: Build failed with an exception.
- What went wrong: Execution failed for task ':Unit_Converter-task:compileTestKotlin'.
Error while evaluating property 'filteredArgumentsMap' of task ':Unit_Converter-task:compileTestKotlin' Could not resolve all files for configuration ':Unit_Converter-task:testCompileClasspath'. > Could not find com.github.hyperskill:hs-test:release-SNAPSHOT. Searched in the following locations: - https://repo.maven.apache.org/maven2/com/github/hyperskill/hs-test/release-SNAPSHOT/maven-metadata.xml - https://repo.maven.apache.org/maven2/com/github/hyperskill/hs-test/release-SNAPSHOT/hs-test-release-SNAPSHOT.pom - https://jitpack.io/com/github/hyperskill/hs-test/release-SNAPSHOT/maven-metadata.xml - https://jitpack.io/com/github/hyperskill/hs-test/release-SNAPSHOT/hs-test-release-v8-g6845035-132-v8-g6845035-132.pom Required by: project :Unit_Converter-task
After sending this output to Jetbrains they requested again to open build.gradle in my project folder and replace testImplementation 'com.github.hyperskill:hs-test:release-SNAPSHOT' with testImplementation 'com.github.hyperskill:hs-test:master-SNAPSHOT'.
This answer took 2-3 days to be replied. After that, the check worked.