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

Offer taikai rules through arch-unit-maven-plugin #42

Open
lobaorn opened this issue Jun 17, 2024 · 2 comments
Open

Offer taikai rules through arch-unit-maven-plugin #42

lobaorn opened this issue Jun 17, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@lobaorn
Copy link

lobaorn commented Jun 17, 2024

Hi there,

I am following the activity in the project, which seems great by the way!

One thing I would like to know if it is been considered already, is providing Taikai with/within arch-unit-maven-plugin: https://github.com/societe-generale/arch-unit-maven-plugin

Because if I have many modules and would like to run against all of them, would be better to run trough the plugin instead of replicating the same rules all over the place.

Do you consider it a feasible idea or do you have another approach in mind?

@mnhock
Copy link
Member

mnhock commented Jun 17, 2024

Hi!

Thanks for your ticket and your suggestion. Yes, I would like to be able to offer something like this. I'm not quite sure yet in which direction this support should go - Maven plugin or something else. Would leave the ticket open until then.

Thank you very much

@piotrooo
Copy link

piotrooo commented Jul 3, 2024

I can share my thoughts on how I currently handle shared rules across multiple repositories (projects). Disclaimer: I use Gradle along with the societe-generale/arch-unit-gradle-plugin.

I've created a rule:

public class SharedRuleTest implements ArchRuleTest {
    @Override
    public void execute(String packagePath, ScopePathProvider scopePathProvider, Collection<String> collection) {
        Taikai.builder()
                .classes(importAllClassesInPackage(scopePathProvider.getMainClassesPath(), packagePath))
                .java(java -> java
                        .fieldsShouldNotBePublic()
                        .utilityClassesShouldBeFinalAndHavePrivateConstructor()
                )
                .logging(logging -> logging
                        .loggersShouldFollowConventions(LoggerFactory.class, "logger", EnumSet.of(PRIVATE, STATIC, FINAL))
                )
                .spring(spring -> spring
                        .noAutowiredFields()
                        .configurations(ConfigurationsConfigurer::namesShouldEndWithConfiguration)
                        .controllers()
                        .services()
                        .repositories()
                )
                .build()
                .check();

        Taikai.builder()
                .classes(importAllClassesInPackage(scopePathProvider.getTestClassesPath(), packagePath))
                .test(test -> test
                        .junit5(junit5 -> junit5
                                .classesShouldBePackagePrivate(".*Test")
                                .methodsShouldBePackagePrivate()
                        )
                )
                .build()
                .check();
    }
}

and use it in the gradle conventions plugins like:

plugins {
    id 'com.societegenerale.commons.arch-unit-gradle-plugin'
}

archUnit {
    preConfiguredRules = [
            'com.thulium.SharedRuleTest',
    ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants