The effective management of diesel quality is not only the fundamental guarantee for the normal operation of diesel engine, but also of realistic significance to protect the environment and personal safety. This paper presented an effective strategy for the rapid classification and determination of the compliance of diesel by using near infrared (NIR) spectroscopy, coupled with Tree-based feature selection (Tree) and popular ensemble learning frameworks. To verify the extrapolation and adaptability of ensemble learning, the light gradient boosting machine (LightGBM), extreme gradient boosting (XGBoost) and adaptive boosting (AdaBoost) which serve as baselines and their combination models with Tree method were developed to establish the models for the classification of diesel brands (case 1: −10#, −20#, −35#, −50# and inferior diesel) and alcohols diesel types (case 2: methanol diesel, ethanol diesel and pure diesel). Satisfactory results showed that all models have achieved acceptable classification results in the above two cases, especially the accuracy of Tree-LightGBM can reach more than 97 % without being affected by data imbalance and spectral overlap. The proposed approach that uses the NIR spectroscopy for diesel brands and types classification can be highly recommended as a practical, convenient, environment friendly and reliable solution for the routine monitoring of diesel market.