Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide an artifact on Maven Central without kotlin-logger and logback dependencies #1875

Closed
leinardi opened this issue Mar 20, 2023 · 16 comments

Comments

@leinardi
Copy link
Contributor

leinardi commented Mar 20, 2023

Expected Behavior

I would like to be able to use KtLint and KtLintRuleEngine in particular, to format some generated code via KotlinPoet without having the standard output of my application spammed with KtLint Logs or having the having the KtLint logging dependencies breaking the logging of my app.

Current Behavior

Currently KtLint depends on io.github.microutils:kotlin-logging-jvm:3.0.5 and ch.qos.logback:logback-classic:1.3.5, while my app is using the new version 4.0.0-beta-23 of kotlin-logging and log4j2 instead of logback.

When I run ktLintRuleEngine.format(file.toPath()), the stdout of my app is spammed with the following logs, one per each file formatted (and I generate thousands of them):

21:16:49.978 [main] DEBUG com.pinterest.ktlint.core.internal.RuleExecutionContext - Editor config properties for file '/home/leinardi/Workspace/gitlab/gtk-kn/bindings/core/gobject/src/nativeMain/kotlin/bindings/gobject/ParamSpecLong.kt': {charset=charset = utf-8, indent_style=indent_style = space, insert_final_newline=insert_final_newline = true, max_line_length=max_line_length = 120, trim_trailing_whitespace=trim_trailing_whitespace = true, ij_continuation_indent_size=ij_continuation_indent_size = 4, ij_formatter_off_tag=ij_formatter_off_tag = @formatter:off, ij_formatter_on_tag=ij_formatter_on_tag = @formatter:on, ij_formatter_tags_enabled=ij_formatter_tags_enabled = true, ij_smart_tabs=ij_smart_tabs = false, ij_visual_guides=ij_visual_guides = 80, 100, 120, ij_wrap_on_typing=ij_wrap_on_typing = false, indent_size=indent_size = 4, tab_width=tab_width = 4, ktlint_standard_enum-entry-name-case=ktlint_standard_enum-entry-name-case = disabled, ij_kotlin_align_in_columns_case_branch=ij_kotlin_align_in_columns_case_branch = false, ij_kotlin_align_multiline_binary_operation=ij_kotlin_align_multiline_binary_operation = false, ij_kotlin_align_multiline_extends_list=ij_kotlin_align_multiline_extends_list = false, ij_kotlin_align_multiline_method_parentheses=ij_kotlin_align_multiline_method_parentheses = false, ij_kotlin_align_multiline_parameters=ij_kotlin_align_multiline_parameters = false, ij_kotlin_align_multiline_parameters_in_calls=ij_kotlin_align_multiline_parameters_in_calls = false, ij_kotlin_allow_trailing_comma=ij_kotlin_allow_trailing_comma = true, ij_kotlin_allow_trailing_comma_on_call_site=ij_kotlin_allow_trailing_comma_on_call_site = true, ij_kotlin_assignment_wrap=ij_kotlin_assignment_wrap = normal, ij_kotlin_blank_lines_after_class_header=ij_kotlin_blank_lines_after_class_header = 0, ij_kotlin_blank_lines_around_block_when_branches=ij_kotlin_blank_lines_around_block_when_branches = 0, ij_kotlin_blank_lines_before_declaration_with_comment_or_annotation_on_separate_line=ij_kotlin_blank_lines_before_declaration_with_comment_or_annotation_on_separate_line = 1, ij_kotlin_block_comment_add_space=ij_kotlin_block_comment_add_space = false, ij_kotlin_block_comment_at_first_column=ij_kotlin_block_comment_at_first_column = true, ij_kotlin_call_parameters_new_line_after_left_paren=ij_kotlin_call_parameters_new_line_after_left_paren = true, ij_kotlin_call_parameters_right_paren_on_new_line=ij_kotlin_call_parameters_right_paren_on_new_line = true, ij_kotlin_call_parameters_wrap=ij_kotlin_call_parameters_wrap = on_every_item, ij_kotlin_catch_on_new_line=ij_kotlin_catch_on_new_line = false, ij_kotlin_class_annotation_wrap=ij_kotlin_class_annotation_wrap = split_into_lines, ij_kotlin_code_style_defaults=ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL, ij_kotlin_continuation_indent_for_chained_calls=ij_kotlin_continuation_indent_for_chained_calls = false, ij_kotlin_continuation_indent_for_expression_bodies=ij_kotlin_continuation_indent_for_expression_bodies = false, ij_kotlin_continuation_indent_in_argument_lists=ij_kotlin_continuation_indent_in_argument_lists = false, ij_kotlin_continuation_indent_in_elvis=ij_kotlin_continuation_indent_in_elvis = false, ij_kotlin_continuation_indent_in_if_conditions=ij_kotlin_continuation_indent_in_if_conditions = false, ij_kotlin_continuation_indent_in_parameter_lists=ij_kotlin_continuation_indent_in_parameter_lists = false, ij_kotlin_continuation_indent_in_supertype_lists=ij_kotlin_continuation_indent_in_supertype_lists = false, ij_kotlin_else_on_new_line=ij_kotlin_else_on_new_line = false, ij_kotlin_enum_constants_wrap=ij_kotlin_enum_constants_wrap = split_into_lines, ij_kotlin_extends_list_wrap=ij_kotlin_extends_list_wrap = on_every_item, ij_kotlin_field_annotation_wrap=ij_kotlin_field_annotation_wrap = normal, ij_kotlin_finally_on_new_line=ij_kotlin_finally_on_new_line = false, ij_kotlin_if_rparen_on_new_line=ij_kotlin_if_rparen_on_new_line = true, ij_kotlin_import_nested_classes=ij_kotlin_import_nested_classes = false, ij_kotlin_imports_layout=ij_kotlin_imports_layout = *, java.**, javax.**, kotlin.**, ^ , ij_kotlin_insert_whitespaces_in_simple_one_line_method=ij_kotlin_insert_whitespaces_in_simple_one_line_method = true, ij_kotlin_keep_blank_lines_before_right_brace=ij_kotlin_keep_blank_lines_before_right_brace = 2, ij_kotlin_keep_blank_lines_in_code=ij_kotlin_keep_blank_lines_in_code = 2, ij_kotlin_keep_blank_lines_in_declarations=ij_kotlin_keep_blank_lines_in_declarations = 2, ij_kotlin_keep_first_column_comment=ij_kotlin_keep_first_column_comment = true, ij_kotlin_keep_indents_on_empty_lines=ij_kotlin_keep_indents_on_empty_lines = false, ij_kotlin_keep_line_breaks=ij_kotlin_keep_line_breaks = true, ij_kotlin_lbrace_on_next_line=ij_kotlin_lbrace_on_next_line = false, ij_kotlin_line_comment_add_space=ij_kotlin_line_comment_add_space = false, ij_kotlin_line_comment_at_first_column=ij_kotlin_line_comment_at_first_column = true, ij_kotlin_method_annotation_wrap=ij_kotlin_method_annotation_wrap = split_into_lines, ij_kotlin_method_call_chain_wrap=ij_kotlin_method_call_chain_wrap = normal, ij_kotlin_method_parameters_new_line_after_left_paren=ij_kotlin_method_parameters_new_line_after_left_paren = true, ij_kotlin_method_parameters_right_paren_on_new_line=ij_kotlin_method_parameters_right_paren_on_new_line = true, ij_kotlin_method_parameters_wrap=ij_kotlin_method_parameters_wrap = on_every_item, ij_kotlin_name_count_to_use_star_import=ij_kotlin_name_count_to_use_star_import = 2147483647, ij_kotlin_name_count_to_use_star_import_for_members=ij_kotlin_name_count_to_use_star_import_for_members = 2147483647, ij_kotlin_parameter_annotation_wrap=ij_kotlin_parameter_annotation_wrap = off, ij_kotlin_space_after_comma=ij_kotlin_space_after_comma = true, ij_kotlin_space_after_extend_colon=ij_kotlin_space_after_extend_colon = true, ij_kotlin_space_after_type_colon=ij_kotlin_space_after_type_colon = true, ij_kotlin_space_before_catch_parentheses=ij_kotlin_space_before_catch_parentheses = true, ij_kotlin_space_before_comma=ij_kotlin_space_before_comma = false, ij_kotlin_space_before_extend_colon=ij_kotlin_space_before_extend_colon = true, ij_kotlin_space_before_for_parentheses=ij_kotlin_space_before_for_parentheses = true, ij_kotlin_space_before_if_parentheses=ij_kotlin_space_before_if_parentheses = true, ij_kotlin_space_before_lambda_arrow=ij_kotlin_space_before_lambda_arrow = true, ij_kotlin_space_before_type_colon=ij_kotlin_space_before_type_colon = false, ij_kotlin_space_before_when_parentheses=ij_kotlin_space_before_when_parentheses = true, ij_kotlin_space_before_while_parentheses=ij_kotlin_space_before_while_parentheses = true, ij_kotlin_spaces_around_additive_operators=ij_kotlin_spaces_around_additive_operators = true, ij_kotlin_spaces_around_assignment_operators=ij_kotlin_spaces_around_assignment_operators = true, ij_kotlin_spaces_around_equality_operators=ij_kotlin_spaces_around_equality_operators = true, ij_kotlin_spaces_around_function_type_arrow=ij_kotlin_spaces_around_function_type_arrow = true, ij_kotlin_spaces_around_logical_operators=ij_kotlin_spaces_around_logical_operators = true, ij_kotlin_spaces_around_multiplicative_operators=ij_kotlin_spaces_around_multiplicative_operators = true, ij_kotlin_spaces_around_range=ij_kotlin_spaces_around_range = false, ij_kotlin_spaces_around_relational_operators=ij_kotlin_spaces_around_relational_operators = true, ij_kotlin_spaces_around_unary_operator=ij_kotlin_spaces_around_unary_operator = false, ij_kotlin_spaces_around_when_arrow=ij_kotlin_spaces_around_when_arrow = true, ij_kotlin_variable_annotation_wrap=ij_kotlin_variable_annotation_wrap = off, ij_kotlin_while_on_new_line=ij_kotlin_while_on_new_line = false, ij_kotlin_wrap_elvis_expressions=ij_kotlin_wrap_elvis_expressions = 1, ij_kotlin_wrap_expression_body_functions=ij_kotlin_wrap_expression_body_functions = 1, ij_kotlin_wrap_first_method_in_call_chain=ij_kotlin_wrap_first_method_in_call_chain = false}
21:16:49.980 [main] DEBUG com.pinterest.ktlint.core.internal.EditorConfigLoader - Resolving .editorconfig files for /home/leinardi/Workspace/gitlab/gtk-kn/bindings/core/gobject/src/nativeMain/kotlin/bindings/gobject/ParamSpecBoolean.kt file path:
	charset: utf-8
	indent_style: space
	insert_final_newline: true
	max_line_length: 120
	trim_trailing_whitespace: true
	ij_continuation_indent_size: 4
	ij_formatter_off_tag: @formatter:off
	ij_formatter_on_tag: @formatter:on
	ij_formatter_tags_enabled: true
	ij_smart_tabs: false
	ij_visual_guides: 80, 100, 120
	ij_wrap_on_typing: false
	indent_size: 4
	tab_width: 4
	ktlint_standard_enum-entry-name-case: disabled
	ij_kotlin_align_in_columns_case_branch: false
	ij_kotlin_align_multiline_binary_operation: false
	ij_kotlin_align_multiline_extends_list: false
	ij_kotlin_align_multiline_method_parentheses: false
	ij_kotlin_align_multiline_parameters: false
	ij_kotlin_align_multiline_parameters_in_calls: false
	ij_kotlin_allow_trailing_comma: true
	ij_kotlin_allow_trailing_comma_on_call_site: true
	ij_kotlin_assignment_wrap: normal
	ij_kotlin_blank_lines_after_class_header: 0
	ij_kotlin_blank_lines_around_block_when_branches: 0
	ij_kotlin_blank_lines_before_declaration_with_comment_or_annotation_on_separate_line: 1
	ij_kotlin_block_comment_add_space: false
	ij_kotlin_block_comment_at_first_column: true
	ij_kotlin_call_parameters_new_line_after_left_paren: true
	ij_kotlin_call_parameters_right_paren_on_new_line: true
	ij_kotlin_call_parameters_wrap: on_every_item
	ij_kotlin_catch_on_new_line: false
	ij_kotlin_class_annotation_wrap: split_into_lines
	ij_kotlin_code_style_defaults: KOTLIN_OFFICIAL
	ij_kotlin_continuation_indent_for_chained_calls: false
	ij_kotlin_continuation_indent_for_expression_bodies: false
	ij_kotlin_continuation_indent_in_argument_lists: false
	ij_kotlin_continuation_indent_in_elvis: false
	ij_kotlin_continuation_indent_in_if_conditions: false
	ij_kotlin_continuation_indent_in_parameter_lists: false
	ij_kotlin_continuation_indent_in_supertype_lists: false
	ij_kotlin_else_on_new_line: false
	ij_kotlin_enum_constants_wrap: split_into_lines
	ij_kotlin_extends_list_wrap: on_every_item
	ij_kotlin_field_annotation_wrap: normal
	ij_kotlin_finally_on_new_line: false
	ij_kotlin_if_rparen_on_new_line: true
	ij_kotlin_import_nested_classes: false
	ij_kotlin_imports_layout: *, java.**, javax.**, kotlin.**, ^ 
	ij_kotlin_insert_whitespaces_in_simple_one_line_method: true
	ij_kotlin_keep_blank_lines_before_right_brace: 2
	ij_kotlin_keep_blank_lines_in_code: 2
	ij_kotlin_keep_blank_lines_in_declarations: 2
	ij_kotlin_keep_first_column_comment: true
	ij_kotlin_keep_indents_on_empty_lines: false
	ij_kotlin_keep_line_breaks: true
	ij_kotlin_lbrace_on_next_line: false
	ij_kotlin_line_comment_add_space: false
	ij_kotlin_line_comment_at_first_column: true
	ij_kotlin_method_annotation_wrap: split_into_lines
	ij_kotlin_method_call_chain_wrap: normal
	ij_kotlin_method_parameters_new_line_after_left_paren: true
	ij_kotlin_method_parameters_right_paren_on_new_line: true
	ij_kotlin_method_parameters_wrap: on_every_item
	ij_kotlin_name_count_to_use_star_import: 2147483647
	ij_kotlin_name_count_to_use_star_import_for_members: 2147483647
	ij_kotlin_parameter_annotation_wrap: off
	ij_kotlin_space_after_comma: true
	ij_kotlin_space_after_extend_colon: true
	ij_kotlin_space_after_type_colon: true
	ij_kotlin_space_before_catch_parentheses: true
	ij_kotlin_space_before_comma: false
	ij_kotlin_space_before_extend_colon: true
	ij_kotlin_space_before_for_parentheses: true
	ij_kotlin_space_before_if_parentheses: true
	ij_kotlin_space_before_lambda_arrow: true
	ij_kotlin_space_before_type_colon: false
	ij_kotlin_space_before_when_parentheses: true
	ij_kotlin_space_before_while_parentheses: true
	ij_kotlin_spaces_around_additive_operators: true
	ij_kotlin_spaces_around_assignment_operators: true
	ij_kotlin_spaces_around_equality_operators: true
	ij_kotlin_spaces_around_function_type_arrow: true
	ij_kotlin_spaces_around_logical_operators: true
	ij_kotlin_spaces_around_multiplicative_operators: true
	ij_kotlin_spaces_around_range: false
	ij_kotlin_spaces_around_relational_operators: true
	ij_kotlin_spaces_around_unary_operator: false
	ij_kotlin_spaces_around_when_arrow: true
	ij_kotlin_variable_annotation_wrap: off
	ij_kotlin_while_on_new_line: false
	ij_kotlin_wrap_elvis_expressions: 1
	ij_kotlin_wrap_expression_body_functions: 1
	ij_kotlin_wrap_first_method_in_call_chain: false

Additional information

  • Current version of ktlint: 0.48.2

I've tried to disable the logs with the following code:

KotlinLogging
    .logger {}
    .setDefaultLoggerModifier { logger ->
        (logger.underlyingLogger as Logger).level = Level.OFF
    }

This works for the logs form KtLint but, unfortunately, the transient dependencies for kotlin-logging and logback are still messing with the rest of the logs of the app (I think kotlin-logging is just using logback and ignoring my configuration for log4j2).

Please consider providing an artifact that can be used to format files from a Java/Kotlin project and that doesn't come with logging dependencies.

EDIT:
I've downgraded kotlin-logging to the same version used by KtLint and the logs still don't work.
I also get these warnings when I add KtLint as depedency:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.jetbrains.kotlin.com.intellij.util.ReflectionUtil (file:/home/leinardi/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-compiler-embeddable/1.8.0/eb9118d4bcceaa2a94b2ae2a33a4ddba7c9a947f/kotlin-compiler-embeddable-1.8.0.jar) to field java.lang.Throwable.backtrace
WARNING: Please consider reporting this to the maintainers of org.jetbrains.kotlin.com.intellij.util.ReflectionUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
@leinardi
Copy link
Contributor Author

Looks like the issue is solved by not importing com.pinterest:ktlint and only importing com.pinterest.ktlint:ktlint-core and com.pinterest.ktlint:ktlint-ruleset-standard.

The warnings seems to be a different issue. More info here: #1618

@paul-dingemans
Copy link
Collaborator

In case other people find this issue:

@leinardi
Copy link
Contributor Author

Hello @paul-dingemans, I have just upgraded to 0.49.0 and unfortunately this issue is back.

After bumping the version I had to import this additional dependencies:

ktlint-cli-ruleset-core = { module = "com.pinterest.ktlint:ktlint-cli-ruleset-core", version.ref = "ktlint" }
ktlint-rule-engine = { module = "com.pinterest.ktlint:ktlint-rule-engine", version.ref = "ktlint" }

in order to be able to import these:

import com.pinterest.ktlint.cli.ruleset.core.api.RuleSetProviderV3
import com.pinterest.ktlint.rule.engine.api.Code
import com.pinterest.ktlint.rule.engine.api.EditorConfigDefaults
import com.pinterest.ktlint.rule.engine.api.KtLintRuleEngine

but now my logs are gone again, replaced by this:

SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.
SLF4J: Class path contains SLF4J bindings targeting slf4j-api versions 1.7.x or earlier.
SLF4J: Ignoring binding found at [jar:file:/home/rleinardi/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-slf4j-impl/2.20.0/7ab4f082fd162f60afcaf2b8744a3d959feab3e8/log4j-slf4j-impl-2.20.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See https://www.slf4j.org/codes.html#ignoredBindings for an explanation.

I guess the source of the issue is here: com.pinterest.ktlint:ktlint-rule-engine depends on ktlintLogger.

The class needed are all inside the package com.pinterest.ktlint.rule.engine.api.*: would it be possible to move them to a separate artifact, like ktlint-rule-engine-api, that doesn't have dependency on ktlintLogger?

@leinardi leinardi reopened this Apr 28, 2023
@paul-dingemans
Copy link
Collaborator

I think this is not the same issue you had before. Previously, you received the logback dependencies as transitive dependency. The logback dependency is only used by the ktlint-cli module. So as long as you do not have a dependency on that module, you won't receive the logback dependency via ktlint.

Currently, the logger just requires any SLF4J implementation to be provided by the API Consumer. Apparently, your project does not provide such a dependency, and as of that it falls back to NOP logger which indeeds results in not displaying any logging. Please try to add any SLF4J logger of your choosing. See example api consumer.

@leinardi
Copy link
Contributor Author

leinardi commented May 5, 2023

Apparently, your project does not provide such a dependency, and as of that it falls back to NOP logger which indeeds results in not displaying any logging.

I'm a little confused: we are providing the following dependencies, shouldn't this be enough?

log4j-api = { module = "org.apache.logging.log4j:log4j-api", version.ref = "log4j" }
log4j-core = { module = "org.apache.logging.log4j:log4j-core", version.ref = "log4j" }
log4j-slf4j-impl = { module = "org.apache.logging.log4j:log4j-slf4j-impl", version.ref = "log4j" }

https://gitlab.com/gtk-kn/gtk-kn/-/blob/feature/ktlint-0.49.0/gradle/libs.versions.toml#L47
https://gitlab.com/gtk-kn/gtk-kn/-/blob/feature/ktlint-0.49.0/gir/build.gradle.kts#L26

Also, one thing that I do not understand is why, after adding the dependency to ktlint-rule-engine, our logs do not work anymore. This was something that was happening also with the previous issue.

@leinardi
Copy link
Contributor Author

leinardi commented May 5, 2023

From what I see by running ./gradlew :gir:dependencies, SLF4J is provided:

+--- org.apache.logging.log4j:log4j-slf4j-impl:2.20.0
|    +--- org.apache.logging.log4j:log4j-api:2.20.0
|    +--- org.slf4j:slf4j-api:1.7.25 -> 2.0.3

Full log:

runtimeClasspath - Runtime classpath of null/main.
+--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.21
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.8.21
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.8.21
|    |    \--- org.jetbrains:annotations:13.0
|    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.21
|         \--- org.jetbrains.kotlin:kotlin-stdlib:1.8.21 (*)
+--- io.github.oshai:kotlin-logging-jvm:4.0.0-beta-28
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.20 -> 1.8.21 (*)
|    \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.8.20 -> 1.8.21
+--- org.apache.logging.log4j:log4j-api:2.20.0
+--- org.apache.logging.log4j:log4j-core:2.20.0
|    \--- org.apache.logging.log4j:log4j-api:2.20.0
+--- org.apache.logging.log4j:log4j-slf4j-impl:2.20.0
|    +--- org.apache.logging.log4j:log4j-api:2.20.0
|    +--- org.slf4j:slf4j-api:1.7.25 -> 2.0.3
|    \--- org.apache.logging.log4j:log4j-core:2.20.0 (*)
+--- com.pinterest.ktlint:ktlint-core:0.49.0
|    +--- org.jetbrains.kotlin:kotlin-compiler-embeddable:1.8.20
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.8.20 -> 1.8.21 (*)
|    |    +--- org.jetbrains.kotlin:kotlin-script-runtime:1.8.20
|    |    +--- org.jetbrains.kotlin:kotlin-reflect:1.6.10 -> 1.8.0
|    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.8.0 -> 1.8.21 (*)
|    |    +--- org.jetbrains.kotlin:kotlin-daemon-embeddable:1.8.20
|    |    +--- org.jetbrains.intellij.deps:trove4j:1.0.20200330
|    |    \--- net.java.dev.jna:jna:5.6.0
|    +--- org.ec4j.core:ec4j-core:0.3.0
|    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.20 -> 1.8.21 (*)
+--- com.pinterest.ktlint:ktlint-cli-ruleset-core:0.49.0
|    +--- com.pinterest.ktlint:ktlint-rule-engine-core:0.49.0
|    |    +--- com.pinterest.ktlint:ktlint-logger:0.49.0
|    |    |    +--- io.github.microutils:kotlin-logging-jvm:3.0.5
|    |    |    |    +--- org.slf4j:slf4j-api:2.0.3
|    |    |    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0 -> 1.8.21 (*)
|    |    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.8.0 -> 1.8.21
|    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.20 -> 1.8.21 (*)
|    |    +--- org.jetbrains.kotlin:kotlin-compiler-embeddable:1.8.20 (*)
|    |    +--- org.ec4j.core:ec4j-core:0.3.0
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.20 -> 1.8.21 (*)
|    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.20 -> 1.8.21 (*)
+--- com.pinterest.ktlint:ktlint-rule-engine:0.49.0
|    +--- com.pinterest.ktlint:ktlint-logger:0.49.0 (*)
|    +--- com.pinterest.ktlint:ktlint-rule-engine-core:0.49.0 (*)
|    +--- org.jetbrains.kotlin:kotlin-compiler-embeddable:1.8.20 (*)
|    +--- org.ec4j.core:ec4j-core:0.3.0
|    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.20 -> 1.8.21 (*)
+--- com.pinterest.ktlint:ktlint-ruleset-standard:0.49.0
|    +--- com.pinterest.ktlint:ktlint-logger:0.49.0 (*)
|    +--- io.github.microutils:kotlin-logging-jvm:3.0.5 (*)
|    +--- com.pinterest.ktlint:ktlint-cli-ruleset-core:0.49.0 (*)
|    +--- com.pinterest.ktlint:ktlint-rule-engine-core:0.49.0 (*)
|    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.20 -> 1.8.21 (*)
+--- com.squareup:kotlinpoet:1.13.1
|    +--- org.jetbrains.kotlin:kotlin-reflect:1.8.0 (*)
|    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0 -> 1.8.21 (*)
+--- org.jetbrains.kotlinx:kotlinx-cli:0.3.5
|    \--- org.jetbrains.kotlinx:kotlinx-cli-jvm:0.3.5
|         +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.6.0 -> 1.8.21
|         \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0 -> 1.8.21 (*)
\--- org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0
     \--- org.jetbrains.kotlinx:kotlinx-serialization-json-jvm:1.5.0
          +--- org.jetbrains.kotlin:kotlin-stdlib:1.8.10 -> 1.8.21 (*)
          +--- org.jetbrains.kotlinx:kotlinx-serialization-bom:1.5.0
          |    +--- org.jetbrains.kotlinx:kotlinx-serialization-core:1.5.0 (c)
          |    +--- org.jetbrains.kotlinx:kotlinx-serialization-json-jvm:1.5.0 (c)
          |    +--- org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0 (c)
          |    \--- org.jetbrains.kotlinx:kotlinx-serialization-core-jvm:1.5.0 (c)
          +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.8.10 -> 1.8.21
          \--- org.jetbrains.kotlinx:kotlinx-serialization-core:1.5.0
               \--- org.jetbrains.kotlinx:kotlinx-serialization-core-jvm:1.5.0
                    +--- org.jetbrains.kotlin:kotlin-stdlib:1.8.10 -> 1.8.21 (*)
                    +--- org.jetbrains.kotlinx:kotlinx-serialization-bom:1.5.0 (*)
                    \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.8.10 -> 1.8.21

Could this be the issue?

+--- com.pinterest.ktlint:ktlint-cli-ruleset-core:0.49.0
|    +--- com.pinterest.ktlint:ktlint-rule-engine-core:0.49.0
|    |    +--- com.pinterest.ktlint:ktlint-logger:0.49.0
|    |    |    +--- io.github.microutils:kotlin-logging-jvm:3.0.5
|    |    |    |    +--- org.slf4j:slf4j-api:2.0.3

@paul-dingemans
Copy link
Collaborator

Also, one thing that I do not understand is why, after adding the dependency to ktlint-rule-engine, our logs do not work anymore. This was something that was happening also with the previous issue.

Did you mean, that your entire project is missing the logs (e.g. not only ktlint logs are missing)?

Could this be the issue?

+--- com.pinterest.ktlint:ktlint-cli-ruleset-core:0.49.0
|    +--- com.pinterest.ktlint:ktlint-rule-engine-core:0.49.0
|    |    +--- com.pinterest.ktlint:ktlint-logger:0.49.0
|    |    |    +--- io.github.microutils:kotlin-logging-jvm:3.0.5
|    |    |    |    +--- org.slf4j:slf4j-api:2.0.3

Sorry, I don't know. But it would be interesting to know whether the issue is caused by a conflict by having bothio.github.microutils:kotlin-logging-jvm:3.0.5 and io.github.oshai:kotlin-logging-jvm:4.0.0-beta-28 in the same project. Could you test what happens when you downgrade to io.github.microutils:kotlin-logging-jvm:3.0.5? As I promissed earlier, ktlint will be migrated to ``io.github.oshai:kotlin-logging-jvm:4.x` once it is out of beta.

@leinardi
Copy link
Contributor Author

leinardi commented May 7, 2023

Did you mean, that your entire project is missing the logs (e.g. not only ktlint logs are missing)?

Yes.

Could you test what happens when you downgrade to io.github.microutils:kotlin-logging-jvm:3.0.5?

I'll test and report back.

@leinardi
Copy link
Contributor Author

leinardi commented May 7, 2023

Btw, using both versions shouldn't be in theory an issue: https://github.com/oshai/kotlin-logging#version-4x-vs-previous-versions

image

@paul-dingemans
Copy link
Collaborator

I am not sure, but I have found two occurrences of logging dependencies that are unwanted and may or may not be related to your problem.

  1. ktlint-ruleset-standard has an unneeded implementation dependency on io.github.microutils:kotlin-logging-jvm:3.0.5 and ktlint-rule-engine has a testImplementation dependency on ktlint-ruleset-standard.
  2. ktlint-test has an api dependency on logback which is only needed for a unit test. The ktlint-rule-engine has a test implementation dependency on ktlint-test.

I will create a PR to resolve above and merge it to master. I will let you know when it is ready. Will you be able to validate against the snapshot build whether this solves your problem?

@paul-dingemans
Copy link
Collaborator

I will create a PR to resolve above and merge it to master. I will let you know when it is ready. Will you be able to validate against the snapshot build whether this solves your problem?

Can you please check whether latest snapshot solves your problem?

@leinardi
Copy link
Contributor Author

leinardi commented May 9, 2023

Can you please check whether latest snapshot solves your problem?

Hi @paul-dingemans, unfortunately not: even with the latest snapshot, logs are completely gone from my app, replaced by these messages:

> Task :gir:run
SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.
SLF4J: Class path contains SLF4J bindings targeting slf4j-api versions 1.7.x or earlier.
SLF4J: Ignoring binding found at [jar:file:/home/rleinardi/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-slf4j-impl/2.20.0/7ab4f082fd162f60afcaf2b8744a3d959feab3e8/log4j-slf4j-impl-2.20.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See https://www.slf4j.org/codes.html#ignoredBindings for an explanation.

I still believe that KtLint artifact should ship without dependencies on kotlin-logging or, if really such dependency is needed, it should be done in a way that works with other versions of kotlin-logging, as stated here.

@paul-dingemans
Copy link
Collaborator

I believe that the way that logging is implemented in ktlint is correct. Ktlint implements logging without depending on a specific implementation of a logger so that the API consumer can freely choose what implementation to use.

The last part of your logs includes following:

SLF4J: Class path contains SLF4J bindings targeting slf4j-api versions 1.7.x or earlier.
SLF4J: Ignoring binding found at [jar:file:/home/rleinardi/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-slf4j-impl/2.20.0/7ab4f082fd162f60afcaf2b8744a3d959feab3e8/log4j-slf4j-impl-2.20.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See https://www.slf4j.org/codes.html#ignoredBindings for an explanation.

this matches with the dependency tree that you posted earlier:

+--- org.apache.logging.log4j:log4j-slf4j-impl:2.20.0
|    +--- org.apache.logging.log4j:log4j-api:2.20.0
|    +--- org.slf4j:slf4j-api:1.7.25 -> 2.0.3

This seems to match with the SLF4J FAQ

I do not see the slf4j-api:1.7.x dependency in the dependency tree of the sample ktlint-api-consumer:

+--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.20
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.8.20
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.8.20
|    |    \--- org.jetbrains:annotations:13.0
|    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.20
|         \--- org.jetbrains.kotlin:kotlin-stdlib:1.8.20 (*)
+--- project :ktlint-logger
|    +--- io.github.microutils:kotlin-logging-jvm:3.0.5
|    |    +--- org.slf4j:slf4j-api:2.0.3 -> 2.0.7
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0 -> 1.8.20 (*)
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.8.0 -> 1.8.20
|    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.20 (*)
+--- project :ktlint-rule-engine
|    +--- project :ktlint-rule-engine-core
|    |    +--- org.jetbrains.kotlin:kotlin-compiler-embeddable:1.8.20
|    |    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.8.20 (*)
|    |    |    +--- org.jetbrains.kotlin:kotlin-script-runtime:1.8.20
|    |    |    +--- org.jetbrains.kotlin:kotlin-reflect:1.6.10
|    |    |    +--- org.jetbrains.kotlin:kotlin-daemon-embeddable:1.8.20
|    |    |    +--- org.jetbrains.intellij.deps:trove4j:1.0.20200330
|    |    |    \--- net.java.dev.jna:jna:5.6.0
|    |    +--- org.ec4j.core:ec4j-core:0.3.0
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.20 (*)
|    |    \--- project :ktlint-logger (*)
|    +--- org.jetbrains.kotlin:kotlin-compiler-embeddable:1.8.20 (*)
|    +--- org.ec4j.core:ec4j-core:0.3.0
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.20 (*)
|    \--- project :ktlint-logger (*)
+--- project :ktlint-ruleset-standard
|    +--- project :ktlint-cli-ruleset-core
|    |    +--- project :ktlint-rule-engine-core (*)
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.20 (*)
|    +--- project :ktlint-rule-engine-core (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.20 (*)
|    \--- project :ktlint-logger (*)
+--- org.slf4j:slf4j-simple:2.0.7
|    \--- org.slf4j:slf4j-api:2.0.7
\--- project :ktlint-test
     +--- org.assertj:assertj-core:3.24.2
     |    \--- net.bytebuddy:byte-buddy:1.12.21
     +--- org.junit.jupiter:junit-jupiter:5.9.2
     |    +--- org.junit:junit-bom:5.9.2
     |    |    +--- org.junit.jupiter:junit-jupiter:5.9.2 (c)
     |    |    +--- org.junit.jupiter:junit-jupiter-api:5.9.2 (c)
     |    |    +--- org.junit.jupiter:junit-jupiter-engine:5.9.2 (c)
     |    |    +--- org.junit.jupiter:junit-jupiter-params:5.9.2 (c)
     |    |    +--- org.junit.platform:junit-platform-commons:1.9.2 (c)
     |    |    \--- org.junit.platform:junit-platform-engine:1.9.2 (c)
     |    +--- org.junit.jupiter:junit-jupiter-api:5.9.2
     |    |    +--- org.junit:junit-bom:5.9.2 (*)
     |    |    +--- org.opentest4j:opentest4j:1.2.0
     |    |    \--- org.junit.platform:junit-platform-commons:1.9.2
     |    |         \--- org.junit:junit-bom:5.9.2 (*)
     |    +--- org.junit.jupiter:junit-jupiter-params:5.9.2
     |    |    +--- org.junit:junit-bom:5.9.2 (*)
     |    |    \--- org.junit.jupiter:junit-jupiter-api:5.9.2 (*)
     |    \--- org.junit.jupiter:junit-jupiter-engine:5.9.2
     |         +--- org.junit:junit-bom:5.9.2 (*)
     |         +--- org.junit.platform:junit-platform-engine:1.9.2
     |         |    +--- org.junit:junit-bom:5.9.2 (*)
     |         |    +--- org.opentest4j:opentest4j:1.2.0
     |         |    \--- org.junit.platform:junit-platform-commons:1.9.2 (*)
     |         \--- org.junit.jupiter:junit-jupiter-api:5.9.2 (*)
     +--- org.codehaus.janino:janino:3.1.9
     |    \--- org.codehaus.janino:commons-compiler:3.1.9
     +--- com.google.jimfs:jimfs:1.2
     |    \--- com.google.guava:guava:30.1-android
     |         +--- com.google.guava:failureaccess:1.0.1
     |         +--- com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
     |         +--- com.google.code.findbugs:jsr305:3.0.2
     |         +--- org.checkerframework:checker-compat-qual:2.5.5
     |         +--- com.google.errorprone:error_prone_annotations:2.3.4
     |         \--- com.google.j2objc:j2objc-annotations:1.3
     +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.20 (*)
     +--- project :ktlint-logger (*)
     +--- project :ktlint-rule-engine (*)
     \--- project :ktlint-cli-ruleset-core (*)

Can you investigate why /home/rleinardi/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-slf4j-impl/2.20.0/7ab4f082fd162f60afcaf2b8744a3d959feab3e8/log4j-slf4j-impl-2.20.0.jar!/org/slf4j/impl/StaticLoggerBinder.class is on your classpath?

@leinardi
Copy link
Contributor Author

leinardi commented May 9, 2023

Can you investigate why /home/rleinardi/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-slf4j-impl/2.20.0/7ab4f082fd162f60afcaf2b8744a3d959feab3e8/log4j-slf4j-impl-2.20.0.jar!/org/slf4j/impl/StaticLoggerBinder.class is on your classpath?

I'm not sure if I got the question right, but log4j is in our classpath because it's what we use as logger (see here) and it works fine with KtLint 0.48.0.

@paul-dingemans
Copy link
Collaborator

To me it looks that org.apache.logging.log4j:log4j-slf4j-impl:2.20.0 which is included in your project results in a transitive dependency org.slf4j:slf4j-api:1.7.25 which is ignored by SLF4J 2.x. You might want to try to exclude that latter dependency so that the org.slf4j:slf4j-api:2.0.x can be picked up.

According to https://logging.apache.org/log4j/2.x/log4j-slf4j-impl.html you also might need to replace log4j-slf4j-impl with log4j-slf4j2-impl.

@leinardi
Copy link
Contributor Author

leinardi commented May 9, 2023

you also might need to replace log4j-slf4j-impl with log4j-slf4j2-impl.

Hey this actually seems to fix the issue! Now the application logs are back and I don't see any additional logs from KtLint 👍

Thanks!

PS
Works also with the latest 0.49.0: no need for the SNAPSHOT.
https://gitlab.com/gtk-kn/gtk-kn/-/merge_requests/76/diffs

@leinardi leinardi closed this as completed May 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants