Em Ae
Em Ae

Reputation: 8704

Checkstyle lexicographical order error

I have following checkstyle configurations.

    <module name="CustomImportOrder">
        <property name="customImportOrderRules"
                  value="STATIC###STANDARD_JAVA_PACKAGE###SPECIAL_IMPORTS###THIRD_PARTY_PACKAGE###SAME_PACKAGE(3)"/>
        <property name="specialImportsRegExp" value="^org\."/>
        <property name="thirdPartyPackageRegExp" value="^com\."/>
        <property name="sortImportsInGroupAlphabetically" value="true"/>
        <property name="separateLineBetweenGroups" value="true"/>
    </module>

and then i have following list of imports

import java.io.IOException;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.commons.lang3.Validate;

import com.google.common.collect.ImmutableMap;

import com.acompanyname.departmentname.commons.exceptions.DependencyFailureException;
import com.acompanyname.departmentname.commons.exceptions.DuplicateRecordException;
import com.acompanyname.departmentname.commons.exceptions.InvalidRequestException;
import com.acompanyname.departmentname.commons.exceptions.RecordNotFoundException;
import com.acompanyname.departmentname.financialservice.domain.Wallet;
import com.acompanyname.departmentname.financialservice.domain.WalletId;
import com.acompanyname.departmentname.financialservice.lambda.Converter;
import com.acompanyname.departmentname.financialservice.lambda.exceptions.DuplicateWalletException;
import com.amazonaws.AmazonClientException;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBSaveExpression;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBScanExpression;
import com.amazonaws.services.dynamodbv2.datamodeling.PaginatedQueryList;
import com.amazonaws.services.dynamodbv2.datamodeling.PaginatedScanList;
import com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException;
import com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue;

for which i am constantly getting error that says Wrong lexicographical order for 'com.acompanyname.departmentname.commons.exceptions.DependencyFailureException' import.

I have tried multiple things and still unable to figure out how to fix this import error. I tried grouping them, re-ordering but still i am so confuse.

Upvotes: 2

Views: 2902

Answers (2)

Nate
Nate

Reputation: 1274

I found out through painful trial and error that the algorithm requires that "jakarta.xml" must come after "java", "javax", and "org". Also, after "org" but before "jakarta" comes your local packages.

Upvotes: 0

Arnaud
Arnaud

Reputation: 17534

The error about the import order of com.acompanyname.departmentname.commons.exceptions.DependencyFailureException is misleading .

The import that actually doesn't respect the lexicographical ordering with your configuration is :

import com.google.common.collect.ImmutableMap;

Upvotes: 1

Related Questions