Use checkstyle to throw error for lombok annotations - checkstyle

I want to throw errors when the #Builder annotation from lombok is used. I couldn't find docs regarding Lombok annotations on checkstyle's website.
Does anyone know how to do that?

Check out and configure IllegalImport and ImportControl to block the imports.
For star imports, you can either disallow star imports with AvoidStarImport, use sevntu's ForbidAnnotationCheck, or use RegexpSingleline as a last resort.

Related

How to fix this error duplicate class found in module class.jar

I got this error when I try to generate signed apk for my project
Duplicate class com.google.android.gms.measurement.AppMeasurement
found in modules classes.jar
(com.google.android.gms:play-services-measurement-impl:16.5.0) and
classes.jar (com.google.firebase:firebase-analytics-impl:10.0.1)
Duplicate class com.google.firebase.analytics.FirebaseAnalytics found
in modules classes.jar
(com.google.android.gms:play-services-measurement-api:16.5.0) and
classes.jar (com.google.firebase:firebase-analytics-impl:10.0.1)
Duplicate class com.google.firebase.analytics.FirebaseAnalytics$Event
found in modules classes.jar
(com.google.android.gms:play-services-measurement-api:16.5.0) and
classes.jar (com.google.firebase:firebase-analytics-impl:10.0.1)
Duplicate class com.google.firebase.analytics.FirebaseAnalytics$Param
found in modules classes.jar
(com.google.android.gms:play-services-measurement-api:16.5.0) and
classes.jar (com.google.firebase:firebase-analytics-impl:10.0.1)
Duplicate class
com.google.firebase.analytics.FirebaseAnalytics$UserProperty found in
modules classes.jar
(com.google.android.gms:play-services-measurement-api:16.5.0) and
classes.jar (com.google.firebase:firebase-analytics-impl:10.0.1)
Go to the documentation to learn how to Fix dependency resolution errors.
how do I fix It?
Try with
implementation("com.google.android.gms:play-services-gcm:$project.playServicesVersion") {
exclude group: 'com.google.android.gms'
}
You can Try including one by one the one which brings errors you apply
implementation("**API**") {
exclude group: 'com.google.android.gms'
}
NB $project.playServicesVersion could be any of your versions you are using
For those who face this type of issue in the future
Ensure that you are using the specific dependency of play services according to your requirements. In my case, I need a map dependency but I am importing the play service dependency which causes duplicate class issues with another firebase dependency.
Use this
def playServiceVersion = "17.0.0"
implementation "com.google.android.gms:play-services-maps:$playServiceVersion"
Instead of
def playServiceVersion = "17.0.0"
implementation "com.google.android.gms:play-services:$playServiceVersion"
For further information check the link below
https://developers.google.com/android/guides/setup
Reason: This error usually occurs due to depedencies using same functionality.
Solution: To revolve such issue is to comment: play-services because play-services-maps has same functions like play-services and also display locations on our android UI system. Please see below for solution.
//implementation 'com.google.android.gms:play-services:12.0.1'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
Also checkout notable transitive dependencies: https://github.com/firebase/FirebaseUI-Android/releases
I hope its help solve so many developers project issues.

Is it a good practice to add redundant #JsonProperty when using JacksonMapper

Is it a good practice to add redundant #JsonProperty when using JacksonMapper? Even if the class vars are same named as the incoming json(and you deserialize the json)?
What can be possible upsides?
What can be possible downsides?
The downside,as you suggested, it's reduandant,especially when this class was replaced from codehaus package to fasterxml so if you have old property you will have to refactor class
org.codehaus.jackson is an older version of Jackson.
com.fasterxml.jackson represents the new project and package.

"Assert in junit.framework has been deprecated" - what next to use?

I bump version of junit to 4.11 and get:
[WARNING] [deprecation] Assert in junit.framework has been deprecated
[WARNING] [deprecation] Assert in junit.framework has been deprecated
....
How and to what migrate?
As it seems the Assert class has been moved from junit.framework to org.junit.Assert in JUnit 4.0 - you can use that instead, it's not deprecated.
Change your import statement from
import junit.framework.Assert;
to
import org.junit.Assert;
and this will rectify your JUnit deprecation warnings.
Both are depricated:
junit.framework.Assert.assertThat
org.junit.Assert.assertThat
According to docs, use Instead:
org.hamcrest.MatcherAssert.assertThat
After facing this problem I have tried lots of ways to solve this but failed again and again.
The good thing is: I have download junit-4.12.jar file from here and added the jar file in the project section under the libs folder. If previously any kind of Junit dependancy exist in the project then remove that from the build.gradle and build + clean your project.
It is worked for me. Hope it will work for you.
Note: Take a look in the image that I attached in below.
Thank you
We had a large number of tests with many assertions.
Adding something like
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
to the import statements also helped to limit the changes in test code.
You can refer to jUnit4 Assert class methods from JUnit4

Fluently choosing which component to inject

I have some components implementing the same interface and I would like to chose which one gets injected to my Repository.
Component.For<IRepository>().ImplementedBy<Repository>().<whatShouldGoHere>()
I thought I had this working with DependsOn but now I saw that DependsOn are for static dependecies such as strings. Is the IHandlerSelector the only way forward? I would rather have the declaration inline with the component registration. Maybe a factory method? Are there any recommendations?
Edit
Example Constructor
public PersitentRepository(Func<ISession,string> sessionFactory)
Digging around I realize that the delegate is an artifact from the TypedFactoryFacility. There seems to have been some change so it now resolves by type only. In older Castle versions the string argument was used to select component by name.
A factory would to the trick.
You need to add the FactorySupportFacility to your container for this to work.
For much more detail, see the Castle Windsor documentation at http://docs.castleproject.org/Default.aspx?Page=Factory-Support-Facility&NS=Windsor&AspxAutoDetectCookieSupport=1.
See also http://www.mail-archive.com/castle-project-users#googlegroups.com/msg04463.html.
DependsOn does work for other things than statics, the problem is that the injected delegate does not resolve the way it used to. I ended up registering my own component for handling this specific delegate
container.Register(Component.for<Func<ISession,string>>().ImplementedBy(sessionName => container.resolve<ISession>(sessionName));
(I typed the above from memory so please excuse any typos)

Using Layout with JMSAppender in Logback

I am using a JMSAppender from the Logback framework to write messages to a Websphere MQ.We have a custom Layout class and have specified it in the config file.However, the layout is not being applied. I read that the JMS appender doesn't really use a Layout class.Is there a way on how I can apply a Layout for the JMSAppender.
Suggestions are welcome.
Thanks in advance.
Although this might be a bit late and you might have figured it out already ....
i was doing some work on JMSAppender lately.
logs are sent to queues as ObjectMessage of type LoggingEventVO which is basically a serializable view of a log entry. you have everything that you need in this instance so a layout/encoder would be irrelevant. On the log consumer side you cast the message to the correct type and produce any format you like there
Take a look at LoggingEventVO src