The extension function of package androidx.navigation have plusAssign, therefore it is equivalent of += but in my code it doesn't find the plusAssign.
class MyNavHostFragment: NavHostFragment() {
override fun createFragmentNavigator(): Navigator<out FragmentNavigator.Destination> {
navController.navigatorProvider += DialogFragmentNavigator(childFragmentManager)
return super.createFragmentNavigator()
}
}
©️ matpag
add below import
import androidx.navigation.plusAssign
Dynamic Feature Module Support
implementation "androidx.navigation:navigation-dynamic-features-fragment:2.3.0-alpha06"
https://developer.android.com/jetpack/androidx/releases/navigation
Related
I have a TeamCity settings.kts code with configuration of build and I want to write a function inside settings.kts or in a file defined next to settings.kts and use the function inside kotlinScript step that is (KotlinScriptCustomBuildStep). How do I call the function (so that I don't need to write big logic inside kotlinScript.content?
//setting.kts
steps {
kotlinScript {
name = "Doing something"
//language=kotlin
content = """
import JiraReport
println(JiraReport().findLastMessage())
....
""".trimIndent()
}
//JiraReport class
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
class JiraReport {
fun findLastMessage(): String {
...
}
This is my world server land plug-in, and I don't know much about gradle and kotlin.(Know some front-end, but every line is like a mountain)
I encountered a problem when compiling. It seems that I lack something called grgit.
How to solve this problem?
Or you can try to compile this project. If you succeed, don't forget to tell me your method. Thank you very much!
import java.time.format.DateTimeFormatter
dependencies {
// Expected everywhere.
compileOnlyApi(libs.checkerqual)
// Minecraft expectations
compileOnlyApi(libs.guava)
compileOnlyApi(libs.gson)
// Platform expectations
compileOnlyApi(libs.snakeyaml)
// Adventure
api(libs.adventure)
api(libs.minimessage)
// Guice
api(libs.guice) {
exclude(group = "com.google.guava")
}
api(libs.guiceassistedinject) {
exclude("com.google.inject", "guice")
}
compileOnlyApi(libs.findbugs)
// Plugins
compileOnlyApi(libs.worldeditCore) {
exclude(group = "bukkit-classloader-check")
exclude(group = "mockito-core")
exclude(group = "dummypermscompat")
}
testImplementation(libs.worldeditCore)
compileOnlyApi(libs.fastasyncworldeditCore) { isTransitive = false }
testImplementation(libs.fastasyncworldeditCore) { isTransitive = false }
// Logging
compileOnlyApi(libs.log4j)
// Other libraries
api(libs.prtree)
api(libs.aopalliance)
api(libs.pipeline) {
exclude(group = "com.google.guava")
}
api(libs.arkitektonika)
api(libs.paster)
}
tasks.processResources {
filesMatching("plugin.properties") {
expand(
"version" to project.version.toString(),
"commit" to rootProject.grgit.head().abbreviatedId, // The error points here
"date" to rootProject.grgit.head().dateTime.format(DateTimeFormatter.ofPattern("yy.MM.dd")) // The error points here
)
}
}
Problems arising
Address of this project: https://github.com/IntellectualSites/PlotSquared
Thanks again!
First, you need to declare the grgit variable before using it, that's why you're getting the error.
Add plugin for grgit in the plugins{} block:
id("org.ajoberstar.grgit") version "4.0.2"
Import Grgit like this:
import org.ajoberstar.grgit.Grgit
Then, declare the variable grgit like this:
val grgit = Grgit.open(mapOf("currentDir" to project.rootDir))
I'm trying to use the Duration class from kotlin.time package like this:
Duration.seconds(5)
But I see Expression 'seconds' cannot be invoked as a function. The function 'invoke()' is not found in my intelliJ.
Not sure, how should I call this function then? Or is there something I'm missing?
For time being I have to use 5.toDuration(DurationUnit.SECONDS)
Snippet:
import kotlin.time.Duration
import kotlin.time.ExperimentalTime
#ExperimentalTime
class Temp {
fun test() {
println(Duration.seconds(5))
}
}
I have kotlin ref in build.gradle.kts file
plugins {
id("org.jetbrains.kotlin.jvm") version "1.5.21"
}
Using it with kotest.
Here are my project dependencies.
dependencies {
testImplementation(kotlin("test-junit5"))
testImplementation("io.kotest:kotest-assertions-core-jvm:$kotestVersion")
testImplementation("io.kotest:kotest-runner-junit5-jvm:$kotestVersion")
testImplementation("io.rest-assured:kotlin-extensions:4.3.0")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.12.+")
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.12.+")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.12.+")
implementation("io.kotest.extensions:kotest-extensions-allure:1.0.1")
}
Make sure you are importing the correct Duration
import kotlin.time.Duration
as there are other Durations.
You can also use the extension function on Int,
import kotlin.time.toDuration
5.toDuration(DurationUnit.SECONDS)
For those looking to use Java Duration, you can do this using #Francesc answer and the information in the link below is (1.toDuration(DurationUnit.SECONDS)).toJavaDuration()
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.time/to-java-duration.html
So I am trying to make a minecraft mod that has a randomly generated ore. I have run into a problem in this part of the code.
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biomes;
import net.minecraft.world.gen.GenerationStage;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.OreFeatureConfig;
import net.minecraft.world.gen.placement.ConfiguredPlacement;
import net.minecraft.world.gen.placement.CountRangeConfig;
import net.minecraft.world.gen.placement.Placement;
import net.minecraftforge.registries.ForgeRegistries;
public class ModOreGen {
public static void generateOre() {
for (Biome biome : ForgeRegistries.BIOMES) {
if (biome == Biomes.BAMBOO_JUNGLE) {
ConfiguredPlacement<CountRangeConfig> customConfig = Placement.COUNT_RANGE
.func_227446_a_(new CountRangeConfig(9, 10, 10, 0));
biome.addFeature(GenerationStage.Decoration.UNDERGROUND_ORES,Feature.ORE.withConfiguration(new OreFeatureConfig(OreFeatureConfig.FillerBlockType.NATURAL_STONE, blockinit.chocolate_ore.getDefaultState(), 10)).withPlacement(customConfig));
}
}
}
}
Where it says .withConfiguration it gives me the error:
The method withConfiguration(OreFeatureConfig) is undefined for the type Feature<OreFeatureConfig>
I have already tried updating my mappings and such, but nothing helped. This has been a problem that has really irritated me for days now. What is happening?
I just had this same problem with my code and finally fixed it. Try this out!
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biomes;
import net.minecraft.world.gen.GenerationStage;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.OreFeatureConfig;
import net.minecraft.world.gen.placement.ConfiguredPlacement;
import net.minecraft.world.gen.placement.CountRangeConfig;
import net.minecraft.world.gen.placement.Placement;
import net.minecraftforge.registries.ForgeRegistries;
public class ModOreGen {
public static void generateOre() {
for (Biome biome : ForgeRegistries.BIOMES) {
if(biome == Biomes.BAMBOO_JUNGLE) {
ConfiguredPlacement<?> customConfig = Placement.COUNT_RANGE
.configure(new CountRangeConfig(9, 10, 10, 0));
biome.addFeature(GenerationStage.Decoration.UNDERGROUND_ORES, Feature.ORE.withConfiguration(newOreFeatureConfig(OreFeatureConfig.FillerBlockType.NATURAL_STONE,BlockInit.chocolate_ore.getDefaultState(), 10)).withPlacement(customConfig));
}
}
}
}
The obvious thing Sammerson did was to remove the strong typing for CountRangeConfig:
ConfiguredPlacement<?> , but that doesn't matter.
What you can't see is updating Forge to 1.15.2.
This is most likely your best fix. In your build.gradle, somewhere near the top (mine is line 28) you've probably already updated your mappings to:
mappings channel: 'snapshot', version: '20200409-1.15.1'
But you also want to go down and update the Forge version also (this is around line 90 for me).
dependencies {
minecraft 'net.minecraftforge:forge:1.15.2-31.1.0'
}
You need to do the same
gradlew genEclipseRuns
gradlew eclipse
just like updating the mappings.
(You can check the Forge page, there may be a newer version than 1.15.2 by the time someone else reads this. And I hope anyone using IntelliJ can figure out how to update your own mappings/forge.))
I am using CSVPrinter class from apache.commons.csv, and I am trying to print some lines in a csv file. As I know, we need to call close() method on a FileWriter, after the writing is done. And based on that assumption, I tried to call CSVPrinter.close().However, IntelliJ IDEA warns me that this method is redundant. Besides, examples in https://www.callicoder.com/java-read-write-csv-file-apache-commons-csv/ does not include this method, either. I want to know why is that method redundant and if I just use .flush() everything will be alright?
Here is an example copied from website mentioned above.
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
public class CSVWriter {
private static final String SAMPLE_CSV_FILE = "./sample.csv";
public static void main(String[] args) throws IOException {
try (
BufferedWriter writer = Files.newBufferedWriter(Paths.get(SAMPLE_CSV_FILE));
CSVPrinter csvPrinter = new CSVPrinter(writer, CSVFormat.DEFAULT
.withHeader("ID", "Name", "Designation", "Company"));
) {
csvPrinter.printRecord("1", "Sundar Pichai ♥", "CEO", "Google");
csvPrinter.printRecord("2", "Satya Nadella", "CEO", "Microsoft");
csvPrinter.printRecord("3", "Tim cook", "CEO", "Apple");
csvPrinter.printRecord(Arrays.asList("4", "Mark Zuckerberg", "CEO", "Facebook"));
csvPrinter.flush();
// I added the following line
csvPrinter.close();
}
}
}
As #user207421 explained in the comments.
First: The try-with-resources statement provides an automatic close at the end of its scope.
Second: Flush is redundant before close.